Page 1 of 1

DzVents Xiaomi Switch

Posted: Monday 11 September 2017 15:18
by Arczipl
Hello,
I have problem with blockly events and I decided to try dzVents. Unfortunately, but it is not understandable to me. Is there anyone who can help me? I have a Xiaomi selector / switch and I would like one click to either turn on 2 lights and turn off depending on whether the device is turned on or off.
I made this code but it does not work and I do not know how to approach it.
Please help

Code: Select all

return {
    active = true,
    on = {
        devices = {
            'XiaomiSwitch'
        }
    },
    execute = function(domoticz, roomSwitch)
        if (roomSwitch.state == 'On' ) then
            domoticz.devices('Lampka Router').switchOn()
            domoticz.notify('This rocks!',
                            'Turns out that it is getting warm here',
                            domoticz.PRIORITY_LOW)
        end
    end
}

Re: DzVents Xiaomi Switch

Posted: Monday 11 September 2017 23:44
by airmarshall
If you are referring to the xiaomi wireless switch then the "On" state doesn't exist. The switch returns 'Click' 'Double Click' 'Long Click' and 'Long Click Release' so you must use those in your code.

Have a look at this and let me know if you need more help:

Code: Select all

 return {
    active = true,
    on = {
        devices = {
            'Wireless Switch 1', 'Wireless Switch 2'
        }
    },
    execute = function(domoticz, switch)
        if (switch.state == 'Click' and domoticz.devices('YLMaster').state == 'Off') then
            domoticz.log('Master Night On')
            domoticz.setScene('Master Red 1%', 'On')
            switch.switchOff()
        elseif (switch.state == 'Click' and domoticz.devices('YLMaster').state == 'On') then
            domoticz.log('YLMaster Off')
            domoticz.devices('YLMaster').switchOff()
            switch.switchOff()
        elseif (switch.state == 'Double Click' and domoticz.devices('YLNursery').state == 'Off') then
            domoticz.log('Nursery Night On')
            domoticz.setScene('Nursery Red 1%', 'On')
            switch.switchOff()
        elseif (switch.state == 'Double Click' and domoticz.devices('YLNursery').state == 'On') then
            domoticz.log('Nursery Night Off')
            domoticz.devices('YLNursery').switchOff()
            switch.switchOff()
        end
    end
}

Re: DzVents Xiaomi Switch

Posted: Tuesday 12 September 2017 15:20
by Arczipl
Sorry but my first time with dzVents and this script it's not clear for me:(

Re: DzVents Xiaomi Switch

Posted: Wednesday 13 September 2017 1:27
by airmarshall
Note the change:

Code: Select all

roomSwitch.state == 'On'
to

Code: Select all

roomSwitch.state == 'Click'
Try this and report back:

Code: Select all

return {
    active = true,
    on = {
        devices = {
            'XiaomiSwitch'
        }
    },
    execute = function(domoticz, roomSwitch)
        if (roomSwitch.state == 'Click' ) then
            domoticz.devices('Lampka Router').switchOn()
            domoticz.notify('This rocks!', 'Turns out that it is getting warm here', domoticz.PRIORITY_LOW)
            roomSwitch.switchOff()
        end
    end
}