hass-virtual
Virtual Components for Home Assistant KT
Virtual components for testing Home Assistant systems.
Table Of Contents
Notes
Wherever you see /config
in this README it refers to your home-assistant
configuration directory. For me, for example, it's /home/steve/ha
that is
mapped to /config
inside my docker container.
Thanks
Many thanks to:
-
JetBrains for the excellent PyCharm IDE and providing me with an open source license to speed up the project development.
Installation
HACS
Virtual is part of the default HACS store. If you're not interested in development branches this is the easiest way to install.
Component Configuration
Add the following to your configuration.yaml
to enable the component:
virtual:
To add multiple components repeat the platform.
switch:
- platform: virtual
name: Switch 1
- platform: virtual
name: Switch 2
Naming
By default, the code creates entities with virtual
as part of their name.
Switch 1
in the previous example will give an entity of
switch.virtual_switch_1
. If you don't want the virtual_
prefix add a !
to the device name. For example:
switch:
- platform: virtual
name: !Switch 1
Avilability
By default, all devices are market as available.
As shown below in each domain, adding initial_availability: false
to configuration can override default and set as unavailable on HA start.
Availability can by set by using the virtual.set_available
with value true
or false
.
This is fully optional and initial_availability
is not requied to be set.
Switches
To add a virtual switch use the following:
switch:
- platform: virtual
name: Switch 1
initial_availability: true
Binary Sensors
To add a virtual binary_sensor use the following. It supports all standard classes.
binary_sensor:
- platform: virtual
name: 'Binary Sensor 1'
initial_value: 'on'
class: presence
initial_availability: true
Use the virtual.turn_on
, virtual.turn_off
and virtual.toggle
services to
manipulate the binary sensors.
Sensors
To add a virtual sensor use the following:
- platform: virtual
name: 'Temperature 1'
class: temperature
initial_value: 37
initial_availability: true
Use the virtual.set
service to manipulate the binary sensors.
Lights
To add a virtual light use the following:
light:
- platform: virtual
name: 'Light 1'
initial_value: 'on'
initial_brightness: 100
support_color: true
initial_color: [0,255]
support_color_temp: true
initial_color_temp: 255
support_white_value: true
initial_white_value: 240
initial_availability: true
Only name
is required.
support_*
; this allows the light to have colour and temperature propertiesinitial_*
; this is to set the initial values.initial_color
is[hue (0-360), saturation (0-100)]
Locks
To add a virtual lock use the following:
lock:
- platform: virtual
name: Front Door Lock
initial_availability: true
Fans
To add a virtual fan use the following:
fan:
- platform: virtual
name: Office Fan
speed: True
speed_count: 5
direction: True
oscillate: True
initial_availability: true
Only name
is required. You only need one of speed
or speed_count
.
speed
; ifTrue
then fan can be set to low, medium and high speedsspeed_count
; number of speeds to allow, these will be broken down into percentages. 4 speeds = 25, 50, 75 and 100%.direction
; ifTrue
then fan can run in 2 directionsoscillate
; ifTrue
then fan can be set to oscillate
Device Tracking
To add a virtual device tracker use the following:
device_tracker:
- platform: virtual
devices:
- virtual_user1
- virtual_user2
They will be moved to home on reboot. Use the device_tracker.see
service to
change device locations.