Controlling Devices

From Yombo
< docs‎ | modules
Jump to: navigation, search

Overview

Controlling automation devices is simple. There are also multiple methods to do so, which allows great flexibility to work within nearly any environment.

Summary of methods to control devices:

  • Within a module, you can quickly control a device with one line:
    • self.Devices['bedroom_table_lamp'].command(cmd='off')
  • Use the local gateway's api:
    • curl https://thehouse.yombo.net:8442/api/v1/devices/bedroom_table_lamp/command/on?apikey=xyz&arguments[not_before]=120&inputs[brightness]=60
      • This will also accept device id and command id.
  • Use YomboBot and Log Reader modules
    • echo "bedroom table lamp off" >> /somepath/somefile.reader
  • Use main Yombo API
    • curl https://api.yombo.net/api/v1/device/deviceIdHash/on?apikey=xyz&arguments[brightness]=60
      • You'll have to use the unique device id, which can be found through the Web Interface.
      • This will also accept a command ID instead of the command name.

Dive deeper

Control within a module

Mostly commonly, devices will be controlled within a module based on automation rules. Things like "turn on the porch light at dusk and turn off at midnight." The follow code shows several ways to handle this:

# First, lets get a device:
table_lamp = self._Devices['bedroom_table_lamp']
# then turn it off
table_lamp.command(cmd='off')
# and back on again in 60 seconds
table_lamp.command(cmd='on', delay=60)

# The above is useful when doing many tasks with a device, however, can it be shortened to:
self.Devices['bedroom_table_lamp'].command(cmd='off')

# Get devices by a specific device type:
10_appliances = self._Devices.search(device_type='x10_appliance')  # Can also search on any device attribute

# Now lets turn off all the x10 appliances that we have.
for appliance in allX10Lamps:
    appliance.command('off')

How do we know when it's dusk? You can keep asking the Times library (which is fine on startup, but not during run-time). can reveal if it's dusk right now or not, but lets used the hook system.

The _time_event_ or _state_set_ hooks can be used to receive notifications of various things. In this example, we will use the _time_event_ hook.

def _time_event_(self, **kwargs):

    # now_twilight_start, now_night, now_day, now_dusk_start
    event = kwargs['value']
    if event == "now_dusk_start":
        self.Devices['house_porch_light_on'].command(cmd='on')
        # now, lets turn off the light at 10pm, but incase we
        # turning it on after 10pm, it shouldn't be on more than
        # 14400 seconds (4 hours).
        off_time = self._Times.get_next_time('10pm', max=14400)
        self.Devices['house_porch_light_on'].command(cmd='off', not_before=off_time)

    # incase it's on for some reason and the sun rises
    if event == "now_dusk_stop":
        self.Devices['house_porch_light_on'].command(cmd='on')

Local API

The gateway includes local API which can perform many functions. Our examples will demonstrate controlling devices from the command prompt of a linux machine, however, the same results can be duplicated using a browser, PHP, Python, etc.

The following demonstrates turning on the bedroom table lamp in 120 seconds from now and sets it to 60%

curl https://thehouse.yombo.net:8442/api/v1/devices/bedroom_table_lamp/command/off?apikey=xyz&arguments[not_before]=120&inputs[brightness]=60

Existing modules

To be completed.

Yombo API

To be completed.

This page was last edited on 28 April 2019.