This is the forum archive of Homey. For more information about Homey, visit the Official Homey website.

The Homey Community has been moved to https://community.athom.com.

This forum is now read-only for archive purposes.
HomeyScript

Stateless virtual device

HomeyRunHomeyRun Member
edited June 2018 in Questions & Help



When a virtual device (light) is created both tags "Turned on" and "Dim level" have no value assigned.

As soon as I toggle the switch the virtual device has a state and the Turned on tag has a value.

I my case I need to get rid of the state. Is there a way with i.e. homeyscript to assign a NULL value to

a device tag or reset the virtual device to stateless again?

 

Tagged:

Comments

  • After browsing through the Web API documentation I was able to construct the answer myself.

    // script searches for deviceid based on the name and reset the onoff value to null which basically means stateless 
    var devicename = 'Kitchen Ceiling';
    let devices = await Homey.devices.getDevices() 
    var device = _.find(devices, function(o) { return o.name == devicename; })
    await Homey.devices.setDeviceCapabilityState({id: device.id,capability: 'onoff', value: null}); 
    let value = await Homey.devices.getDeviceCapabilityState({id: device.id,capability: 'onoff'})
    console.log(value)
    return true

  • HomeyRun said:
    After browsing through the Web API documentation I was able to construct the answer myself.

    // script searches for deviceid based on the name and reset the onoff value to null which basically means stateless 
    var devicename = 'Kitchen Ceiling';
    let devices = await Homey.devices.getDevices() 
    var device = _.find(devices, function(o) { return o.name == devicename; })
    await Homey.devices.setDeviceCapabilityState({id: device.id,capability: 'onoff', value: null}); 
    let value = await Homey.devices.getDeviceCapabilityState({id: device.id,capability: 'onoff'})
    console.log(value)
    return true

    Can you give me a little bit more context/explanation.

    This was my use-case from the other topic:

    I'm trying to have Alexa properly turning on my Hi-fi. 
    Simple virtual device (switch) since Buttons are not supported by Alexa.
    If switch is turned on - sent command to receiver to be switched on
    If switch is turned off - sent command to receiver to be switched off
    easy. 
    Now, the Hifi can be turned on/off manually. Which results in the switch being switched off manually and if set to off by Alexa, it doesn't trigger. It was already turned off and visa versa. The virtual switch and the state of the device are no longer in sync.
    I thought, lets use my power meter to detect whether the device is actually on. But then I get into loops and all kind of issues.
    How did you guys do it?


    When do I make the device stateless(null). In what situation/flow.
  • Problem is that Homey wants to be the master.
    This means that Homey will keep track of the state of a device.
    If the state of your virtual device is off and you ask Alexa to turn off that same virtual device then Alexa
    will confirm your command with "ok" but nothing will happen.

    After every state change of your virtual device you need to make the device state null.
    Your virtual device will then always respond to every Alexa request (on and off)

    You need to execute the example code as part of the every workflow that is triggered by your virtual device

  • HomeyRun said:
    Problem is that Homey wants to be the master.
    This means that Homey will keep track of the state of a device.
    If the state of your virtual device is off and you ask Alexa to turn off that same virtual device then Alexa
    will confirm your command with "ok" but nothing will happen.

    After every state change of your virtual device you need to make the device state null.
    Your virtual device will then always respond to every Alexa request (on and off)

    You need to execute the example code as part of the every workflow that is triggered by your virtual device

    get it! Awesome. Will test it when I have time.

Sign In or Register to comment.