Page 1 of 1

Selector dzvents

Posted: Thursday 08 February 2018 12:49
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

Re: Selector dzvents

Posted: Thursday 08 February 2018 12:50
by emme
domoticz.device('myHeatSelector').switchSelector(10)
domoticz.devices('mySetPoint').updateSetPoint(domoticz.device('myHeatSelector').levelName)

Re: Selector dzvents

Posted: Thursday 08 February 2018 13:38
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

Re: Selector dzvents

Posted: Thursday 08 February 2018 13:51
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

Re: Selector dzvents

Posted: Thursday 08 February 2018 14:55
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

Re: Selector dzvents

Posted: Thursday 08 February 2018 15:07
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

Re: Selector dzvents

Posted: Thursday 08 February 2018 15:26
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

Re: Selector dzvents

Posted: Thursday 08 February 2018 16:13
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
}

Re: Selector dzvents

Posted: Friday 09 February 2018 11:55
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.

Re: Selector dzvents

Posted: Saturday 17 February 2018 0:38
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 4923 times
https://www.domoticz.com/wiki/DzVents:_ ... or_etc..29