Selector dzvents

Easy to use, 100% Lua-based event scripting framework.
Post Reply
parrotface
Posts: 46
Joined: Monday 02 February 2015 16:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Selector dzvents

Post by parrotface » Thursday 08 February 2018 13:49

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: 798
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Selector dzvents

Post by emme » Thursday 08 February 2018 13:50

domoticz.device('myHeatSelector').switchSelector(10)
domoticz.devices('mySetPoint').updateSetPoint(domoticz.device('myHeatSelector').levelName)
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

parrotface
Posts: 46
Joined: Monday 02 February 2015 16:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Re: Selector dzvents

Post by parrotface » Thursday 08 February 2018 14:38

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: 798
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Selector dzvents

Post by emme » Thursday 08 February 2018 14:51

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
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

parrotface
Posts: 46
Joined: Monday 02 February 2015 16:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Re: Selector dzvents

Post by parrotface » Thursday 08 February 2018 15:55

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: 46
Joined: Monday 02 February 2015 16:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Re: Selector dzvents

Post by parrotface » Thursday 08 February 2018 16:07

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: 46
Joined: Monday 02 February 2015 16:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Re: Selector dzvents

Post by parrotface » Thursday 08 February 2018 16:26

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: 798
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Selector dzvents

Post by emme » Thursday 08 February 2018 17:13

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
}
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

parrotface
Posts: 46
Joined: Monday 02 February 2015 16:50
Target OS: Linux
Domoticz version:
Location: Cheshire England
Contact:

Re: Selector dzvents

Post by parrotface » Friday 09 February 2018 12:55

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: 49
Joined: Saturday 25 November 2017 18:18
Target OS: Raspberry Pi
Domoticz version: v3.8153
Location: Czech Rep.
Contact:

Re: Selector dzvents

Post by kimot » Saturday 17 February 2018 1:38

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 445 times
https://www.domoticz.com/wiki/DzVents:_ ... or_etc..29

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest