All Projects → twrecked → hass-virtual

twrecked / hass-virtual

Licence: GPL-3.0 License
Virtual Components for Home Assistant

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

hass-virtual

Virtual Components for Home Assistant

Virtual components for testing Home Assistant systems.

Table Of Contents

  1. Notes
  2. Thanks
  3. Installation
    1. Manually
    2. From Script
  4. Component Configuration

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.

    JetBrains

Installation

HACS

hacs_badge

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 properties
  • initial_*; 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; if True then fan can be set to low, medium and high speeds
  • speed_count; number of speeds to allow, these will be broken down into percentages. 4 speeds = 25, 50, 75 and 100%.
  • direction; if True then fan can run in 2 directions
  • oscillate; if True 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].