Page 1 of 1

How to use the value of 'Set Level' in a Action ?

Posted: Tuesday 11 December 2018 2:51
by costo
Hi,
My Hardware: RasPi3b with V4.10241 with MQTT client Gateway and a lot of ESP8266 modules.

I created two virtual dimmers. One as Dummy by 'hardware-Create Virtual Sensor' type=Light/Switch named test1 and the other as Virtual by 'Add Manual Light/Switch Device' type=Lightning2 named test2. If I click on the slider the percentage changes as expected but what I see in the log puzzles me.

The first generates these 2 lines:
2018-12-11 02:34:13.548 (Virtual) Light/Switch (test1)
2018-12-11 02:34:13.541 Status: User: Admin initiated a switch command (751/test1/Set Level)

the second generates these 2 lines:
2018-12-11 02:34:17.931 (Virtual) Lighting 2 (test2)
2018-12-11 02:34:17.924 Status: User: Admin initiated a switch command (752/test2/Set Level)

What I expected to be a variable or a parameter is displayed as Set Level, not the percentage from the slider.

I want to sent the percentage value of the slider with an ON Action/Off Action to a ESP8266 with ESPEasy Firmware. The Action I use should be something like this:
On Action: http://192.168.178.112/control?cmd=EXTPWM,105,Set_Level, where Set_Level should be the numeric value of the slider.

How can I use the value of 'Set Level' in a Action?

Re: How to use the value of 'Set Level' in a Action ?

Posted: Tuesday 11 December 2018 8:23
by waaren

costo wrote: I want to sent the percentage value of the slider
How can I use the value of 'Set Level' in a Action?
Probably only using a script triggered by the device change.
Then you could also choose between HTTP and MQTT for sending the information

Re: How to use the value of 'Set Level' in a Action ?

Posted: Tuesday 11 December 2018 13:26
by costo
waaren thanx for your reaction.

Documentation on the "Set Level" variable is very fuzzy.

I have been looking at scripts, but at the moment I cannot figure out how to implement this..
I am looking for a very simple script which could sent a http command line like if it was an On/Off Action.
I can think of something simple like this:

commandArray = {}
ESPEasy_ip = '192.168.178.112'
cmd = 'curl "http://' .. ESPEasy_ip .. '/control?cmd=EXTPWM,105,' .. Set Level .. '"'
os.execute(cmd)
return commandArray

This gives Error: EventSystem: in ESPEasy: [string "commandArray = {}..."]:3: syntax error near '..'

edit:

I can manipulate the script so the scripterror disappears but then the next error is:
2018-12-11 13:58:48.336 Error: SQLHelper: Error script not found '/home/pi/domoticz/scripts/ESPEasy'

I saved the script as ESPEasy and called it with On Action: script://ESPEasy.

It looks like an Action command is not the way to solve this.

Re: How to use the value of 'Set Level' in a Action ?

Posted: Thursday 13 December 2018 2:08
by costo
I found a solution with the "LUA-device" example script that I changed a bit

Code: Select all

ESPEasy_ip = '192.168.178.40'  

commandArray = {}

for deviceName,deviceValue in pairs(devicechanged) do          -- loop through all the changed devices
    if (deviceName=='test1') then          -- my dimmer device
        local a = (tostring(deviceValue))   -- Set Level: nn% / On / Off

        if a == "On" or a == 'Off' then      -- if no number a must be 0
            a = 0
        end
        
        local percentage = (tonumber(string.match(a,'%d[%d]*')))        -- extracts number from string 
        cmd = 'curl "http://'..ESPEasy_ip..'/control?cmd=EXTGPIO,100,'..percentage..'"' -- send to ESP
        os.execute(cmd)
    end
end

return commandArray

Re: How to use the value of 'Set Level' in a Action ?

Posted: Thursday 13 February 2020 12:20
by Thuis
costo wrote: Thursday 13 December 2018 2:08 I found a solution with the "LUA-device" example script that I changed a bit

Code: Select all

ESPEasy_ip = '192.168.178.40'  

commandArray = {}

for deviceName,deviceValue in pairs(devicechanged) do          -- loop through all the changed devices
    if (deviceName=='test1') then          -- my dimmer device
        local a = (tostring(deviceValue))   -- Set Level: nn% / On / Off

        if a == "On" or a == 'Off' then      -- if no number a must be 0
            a = 0
        end
        
        local percentage = (tonumber(string.match(a,'%d[%d]*')))        -- extracts number from string 
        cmd = 'curl "http://'..ESPEasy_ip..'/control?cmd=EXTGPIO,100,'..percentage..'"' -- send to ESP
        os.execute(cmd)
    end
end

return commandArray
Maybe? a bit late, but thank you very much it works like a charm :-)