Selector dzvents

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
parrotface
Posts: 36
Joined: Monday 02 February 2015 15:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Selector dzvents

Post by parrotface »

I am struggling with a selector switch
I am trying to change my heating zones with a selector switch. I can do with separate switches
Do I have to use the value it has created i.e. 10 20 30 etc
if so what is the correct syntax to read the various buttons of the selector switch
Thanks
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Selector dzvents

Post by emme »

domoticz.device('myHeatSelector').switchSelector(10)
domoticz.devices('mySetPoint').updateSetPoint(domoticz.device('myHeatSelector').levelName)
The most dangerous phrase in any language is:
"We always done this way"
parrotface
Posts: 36
Joined: Monday 02 February 2015 15:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Re: Selector dzvents

Post by parrotface »

Thanks for reply
my test code

return {
active = true,
on = {
devices = {
'boost test 126', -- name of switch
'selector', -- name of selector switch
},
timer = {'every 1 minutes'}
},

execute = function(domoticz, device, triggerInfo)
domoticz.log('trigger == > '..triggerInfo.type)

if triggerInfo.type == domoticz.EVENT_TYPE_TIMER then
-- do timer event stuff
domoticz.log(' tttttt Hey! timer ttttttttttttttttttt')
elseif triggerInfo.type == domoticz.EVENT_TYPE_DEVICE then
-- do device event stuff
if (device.state == 'On') then
domoticz.log('Hey! I am on! xxxxxxx Switch On xxxxxxxxxxxxxxxxxxxxxxx')
print " on "
else
domoticz.log('Hey! I am off! yyyyyyyy Switch Off Off Off Switch Off Off Off ')
end

if domoticz.device('selector').switchSelector(10) then
domoticz.log('its 10 ')
elseif domoticz.device('selector').switchSelector(20) then
domoticz.log('its 20 ')
end
domoticz.log(domoticz.devices('selector').value)
end

end
}


log
2018-02-08 12:37:08.159 dzVents: Info: ------ Start internal script: selector: Device: "selector (dummy1)", Index: 871
2018-02-08 12:37:08.159 Error: dzVents: Error: An error occured when calling event handler selector
2018-02-08 12:37:08.159 Error: dzVents: Error: .../domoticz/scripts/dzVents/generated_scripts/selector.lua:19: attempt to index global 'domoticz' (a nil value)
2018-02-08 12:37:08.159 dzVents: Info: ------ Finished selector

thanks
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Selector dzvents

Post by emme »

need to know exactely where is line 19 but I assume is on the if statement
as per dzvents 2.4.1 the triggerInfo is depreciated (but still valid)
try to replace
elseif triggerInfo.type == domoticz.EVENT_TYPE_DEVICE then
with
elseif device.isDevice then
The most dangerous phrase in any language is:
"We always done this way"
parrotface
Posts: 36
Joined: Monday 02 February 2015 15:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Re: Selector dzvents

Post by parrotface »

Thanks

changed elseif and its now working OK

was --elseif triggerInfo.type == domoticz.EVENT_TYPE_DEVICE then
now elseif device.isDevice then

Thanks for your fast help been struggling for nearly a week and you fixed in minutes.
Out of interest where do I find information for these types of situations
Thanks again
parrotface
Posts: 36
Joined: Monday 02 February 2015 15:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Re: Selector dzvents

Post by parrotface »

Hi
I think I spoke too soon it's not working now don't know what is happening

errors
2018-02-08 14:02:26.462 Error: dzVents: Error: An error occured when calling event handler hall
2018-02-08 14:02:26.462 Error: dzVents: Error: ...e/pi/domoticz/scripts/dzVents/generated_scripts/hall.lua:28: attempt to call field 'device' (a nil value)

Code

return {
active = true,
on = {
devices = {
'boost test 126', -- name of switch
'selector', -- name of selector switch
},
timer = {'every 1 minutes'}
},

execute = function(domoticz, device, triggerInfo)
domoticz.log('trigger == > '..triggerInfo.type)

if triggerInfo.type == domoticz.EVENT_TYPE_TIMER then
-- do timer event stuff
domoticz.log(' tttttt Hey! timer ttttttttttttttttttt')
--elseif triggerInfo.type == domoticz.EVENT_TYPE_DEVICE then
elseif device.isDevice then
-- do device event stuff
if (device.state == 'On') then
domoticz.log('Hey! I am on! xxxxxxx Switch On xxxxxxxxxxxxxxxxxxxxxxx')
print " on "
else
domoticz.log('Hey! I am off! yyyyyyyy Switch Off Off Off Switch Off Off Off ')
end

if domoticz.device('selector').switchSelector(10) then -- THIS IS LINE 28
domoticz.log('its 10 ')
elseif domoticz.device('selector').switchSelector(20) then
domoticz.log('its 20 ')
end
domoticz.log(domoticz.devices('selector').value)
end

end
}

Note the error is now line 28 - indicated in code above

Thanks
parrotface
Posts: 36
Joined: Monday 02 February 2015 15:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Re: Selector dzvents

Post by parrotface »

Update errors have disappeared but the if section line 28 is not doing anything

also tried
if domoticz.devices('selector').value == "Breakfast" then
domoticz.log('its Breakfast')
end

the following line returns Breakfast
domoticz.log(domoticz.devices('selector').value)


following copied from switch
Selector Levels:
Level Level name Order
0 Off
10 Breakfast [Rename] [Delete]
20 Snug [Rename] [Delete]
30 Hall [Rename] [Delete]
40 Lounge [Rename] [Delete]
50 Dinning [Rename] [Delete]

Thanks
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Selector dzvents

Post by emme »

uh.. this is a wired behavior.... it should be not supposed to act like this...

first of all.. what version are you running?
as per dzVents 2.4 ( https://www.domoticz.com/wiki/DzVents:_ ... _scripting ) your script should look like:

Code: Select all

return {
    active = true,
    on = {
    devices = {
        'boost test 126', -- name of switch
        'selector', -- name of selector switch
    },
    timer = {'every 1 minutes'}
    },

execute = function(domoticz, device ) 

    domoticz.log('trigger == > '..device.trigger)
    
    if device.isTimer then
        -- do timer event stuff
        domoticz.log(' tttttt Hey! timer ttttttttttttttttttt')
        --elseif triggerInfo.type == domoticz.EVENT_TYPE_DEVICE then
    elseif device.isDevice then 
        -- do device event stuff
        if (device.state ~= 'Off') then
            domoticz.log('Hey! Not sure I\'m on.. anyhow, if I am a selector, I\'m NOT off!! xxxxxxx Switch On xxxxxxxxxxxxxxxxxxxxxxx')
        else
            domoticz.log('Hey! I am off! yyyyyyyy Switch Off Off Off Switch Off Off Off ')
        end
    
        if domoticz.device('selector').level == 10 then -- THIS IS LINE 28
            domoticz.log('its 10 ')
        elseif domoticz.device('selector').level == 20 then 
            domoticz.log('its 20 ') 
        end
        domoticz.log(domoticz.devices('selector').value)
        domoticz.log(domoticz.devices('selector').levelName)
    end

end
}
The most dangerous phrase in any language is:
"We always done this way"
parrotface
Posts: 36
Joined: Monday 02 February 2015 15:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Re: Selector dzvents

Post by parrotface »

seem to have solve part of the problem an works for what I need at the moment

if domoticz.devices('selector').state == 'Breakfast' then --- this works OK

also domoticz.devices('selector').levelName) -- returns Breakfast

but domoticz.devices('selector').value -- or .Value Does Not work

at least I can get the name of selector but not the value but I can work around that.

Many Thanks again for all your help and hopefully I will be able to boost my heating in different zones now just using a single selector.
kimot
Posts: 105
Joined: Saturday 25 November 2017 17:18
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8153
Location: Czech Rep.
Contact:

Re: Selector dzvents

Post by kimot »

Here is my way, how I send selector value ( 0, 10, 20,... ) to ESPEasy.

For inspiration part of code my "every minute" script, which send state of selector to ESPeasy every minute.

Code: Select all

 local mode = domoticz.devices('Filip_Control')
            local url2= 'http://192.168.1.105/control?cmd=event,modeSet='..(mode.level)..''
            print(url2)
            domoticz.openURL(url2)
I think
".level" is what you looking for.
In my case I am sending:
http://192.168.1.105/control?cmd=event,modeSet=0
or
http://192.168.1.105/control?cmd=event,modeSet=10
or
http://192.168.1.105/control?cmd=event,modeSet=20
according selector state.
o1.png
o1.png (341.11 KiB) Viewed 4843 times
https://www.domoticz.com/wiki/DzVents:_ ... or_etc..29
RPi2 Domoticz v 4.10717
10 x Sonoff Basic - ESPeasy
1 x Wemos D1 - ESPeasy
1 x Shelly Plus Plug S
1 x Sonoff S26 - ESPeasy
1 x Shelly 1
1 x MySensors HC-SR04
1 x MySenosrs wifi gateway
1 x RFLink
4x Cam IPC-T240H
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest