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

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
costo
Posts: 71
Joined: Tuesday 11 August 2015 17:35
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

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

Post 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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
costo
Posts: 71
Joined: Tuesday 11 August 2015 17:35
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

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

Post 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.
costo
Posts: 71
Joined: Tuesday 11 August 2015 17:35
Target OS: Linux
Domoticz version: 2025.1
Location: Netherlands
Contact:

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

Post 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
User avatar
Thuis
Posts: 281
Joined: Tuesday 11 September 2018 11:36
Target OS: Linux
Domoticz version: Beta
Location: The Netherlands
Contact:

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

Post 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 :-)
If you can not handle a computer, you buy a Mac. If you can not handle domotica, you use Homeassistant!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest