Page 1 of 1

Blockly script for switching off Yeelight with 433 remote

Posted: Thursday 10 January 2019 23:25
by gschmidt
Hi,

I wondered if I could make a blockly script which turns of a Yeelight LED Bulb lamp with a 433mhz remote button.

First I learned the 433 mhz remote button in the switches page, and it created a on\off switch automatically.
I called the switch "Yeelights AB", and turning the switch on and off with the remote button is working.

I also have a Yeelight LED Bulb RGBWW wifi lamp.
For this lamp I have created a light/switch, selector switch, dimmer (Hoek Lamp 1) with a virtual switch.
With a dzVents script I control this lamp. Also working (see code below)

Code: Select all

return {
    active = true,
    on = { 
        devices = { 'Hoek Lamp 1'}
    },
    execute = function(domoticz, device)
        port = '55443'
        yeelights = {'192.168.1.57'}
        for ix, ipadress in ipairs(yeelights) do
            if (device.state == 'Off') then
                domoticz.log('Turning light off')
                runcommand = "sudo echo -ne '{\"id\":1,\"method\":\"set_power\", \"params\":[\"off\", \"smooth\", 500]}\\r\\n' | nc -w1 " ..ipadress.." " ..port..""
                os.execute(runcommand)
            else
                domoticz.log('Changing brightness level')
                brightvalue = (device.level - 1);
                runcommand = "sudo echo -ne '{\"id\":1, \"method\":\"set_scene\",\"params\":[\"ct\",2950, " .. brightvalue .. "]}\\r\\n' | nc -w1 " ..ipadress.." " ..port..""
                os.execute(runcommand)
            end
        end
    end
}
Next step I created a Blockly script (see attachment), but the Yeelight is not responding when the On/Off Switch is turned on or off...
What am I missing here?

Greetzzz,

Gerben

Re: Blockly script for switching off Yeelight with 433 remote

Posted: Friday 11 January 2019 5:27
by welby
Do you have it set to activate from a device on the right hand side?

Re: Blockly script for switching off Yeelight with 433 remote

Posted: Friday 11 January 2019 7:30
by gschmidt
Sorry I am not experienced yet in domoticz, what do you mean with "from a device on the right hand side"?

Re: Blockly script for switching off Yeelight with 433 remote

Posted: Friday 11 January 2019 8:13
by waaren
Depending on your domoticz version but in latest Beta and versions from before 10 weeks ago you can choose how Blockly scripts are to be triggered.
Either by Time, Device, Security, User variable or All. For this Blockly the logical choose would be Device.

What complicates the answer that this option was removed when the new event editor became active in beta's somewhere in november 2018 and the option came back in Version: 4.10341

Re: Blockly script for switching off Yeelight with 433 remote

Posted: Friday 11 January 2019 17:09
by gschmidt
I have beta version 4.10304
But in my UI in the events manager only the lua and dzVents script have those options.
For the Yeelights dzVents scripts i created, I also did select Device.
Can you maybe upload a screenshot where i can select "Device" when creating a blockly script?

Re: Blockly script for switching off Yeelight with 433 remote

Posted: Friday 11 January 2019 18:05
by waaren
Sure I am on V4.10343
Including trigger selector
Including trigger selector
blockly.png (59.99 KiB) Viewed 728 times

Re: Blockly script for switching off Yeelight with 433 remote

Posted: Friday 11 January 2019 18:27
by gschmidt
Ok , I have the same UI.
Suddenly it is working... :o
No idea why it first did'nt

Thanx for helping anyway