Coder Social home page Coder Social logo

hass-virtual's Introduction

hass-virtual

Virtual Components for Home Assistant

Virtual components for testing Home Assistant systems.

Version 0.8

Breaking Changes

I've added persistent support to binary_sensor, fan, light, lock, sensor, switch and device_tracker. The persistent saving of state is turned on by default. If you do not want this set persistent: False in the entity configuration.

Table Of Contents

  1. Notes
  2. Thanks
  3. Installation
  4. Component Configuration
    1. Naming
    2. Availability
    3. Peristence
    4. The Components...

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 licence 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

Availability

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 required to be set.

Persistence

By default, all device states are persistent. You can change this behaviour with the persistent configuration option.

If you have set an initial_value it will only be used if the device state is not restored. The following switch will always start on.

switch:
  - platform: virtual
    name: Switch 1
    persistent: False
    initial_value: on

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
  unit_of_measurement: 'F'

Use the virtual.set service to manipulate the sensor value.

Setting unit_of_measurement can override default unit for selected sensor class. This is optional ans any string is accepted. List of standard units can be found here: Sensor Entity

Lights

To add a virtual light use the following:

light:
  - platform: virtual
    name: 'Light 1'
    initial_value: 'on'
    support_brightness: true
    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)]

Note; *white_value is deprecated and will be removed in future releases.

Locks

To add a virtual lock use the following:

lock:
  - platform: virtual
    name: Front Door Lock
    initial_availability: true
    initial_value: locked
    locking_time: 5
    jamming_test: 5
  • Persistent Configuration
    • initial_availibilty: optional, default True; is device available at start up
    • initial_value: optional, default locked; any other value will result in the lock being unlocked at start up
  • Per Run Configuration
    • name: required; device name
    • locking_time: optional, default 0 seconds; any positive value will result in a locking or unlocking phase that lasts locking_time seconds
    • jamming_test: optional, default 0 tries; any positive value will result in a jamming failure approximately once per jamming_test tries

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:
      - name: virtual_user1
        peristent: True
        location: home
      - name: virtual_user2
        peristent: False
        location: not_home

Only name is required.

  • persistent: default True; if True then entity location is remembered across restarts otherwise entity always starts at location
  • location: default home; this sets the device location when it is created or if the device is not persistent

Use the device_tracker.see service to change device locations.

Old Style Configuration

The old style configuration will still work. They will be moved to home on initial creation and their location will survive restarts.

device_tracker:
  - platform: virtual
    devices:
      - virtual_user1
      - virtual_user2

hass-virtual's People

Contributors

twrecked avatar tony763 avatar matthewmmorrow avatar camtosh avatar digitalralf avatar nechry avatar wrt54g avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.