Virtual components for testing Home Assistant systems.
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.
Many thanks to:
-
JetBrains for the excellent PyCharm IDE and providing me with an open source license to speed up the project development.
Virtual is part of the default HACS store. If you're not interested in development branches this is the easiest way to install.
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
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
To add a virtual switch use the following:
switch:
- platform: virtual
name: Switch 1
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
Use the virtual.turn_on
, virtual.turn_off
and virtual.toggle
services to
manipulate the binary sensors.
To add a virtual sensor use the following:
- platform: virtual
name: 'Temperature 1'
class: temperature
initial_value: 37
Use the virtual.set
service to manipulate the binary sensors.
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
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)]
To add a virtual lock use the following:
lock:
- platform: virtual
name: Front Door Lock
To add a virtual fan use the following:
fan:
- platform: virtual
name: Office Fan
speed: True
direction: True
oscillate: True
Only name
is required.
speed
; ifTrue
then fan can be set to low, medium and high speedsdirection
; ifTrue
then fan can run in 2 directionsoscillate
; ifTrue
then fan can be set to oscillate
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.