Can a selector levelname be changed with script?
Moderator: leecollings
-
- Posts: 270
- Joined: Thursday 14 March 2024 10:11
- Target OS: Linux
- Domoticz version: 2025.1
- Location: Netherlands
- Contact:
Can a selector levelname be changed with script?
I am experimenting with a selector switch and I would like to be able to dynamically set the level name (in my case only for level 0).
Then setting to level = 0 when it is OFF with a certain levelname, while changing to another level (with the same levelname) sets it ON.
That state (On or Off) is visible for the human eye when you look at the icon and it is visible by the script where level == 0 or level > 0.
I did not find a way to change levelname of a selector switch with DzVents.
Anyone with an idea?
Then setting to level = 0 when it is OFF with a certain levelname, while changing to another level (with the same levelname) sets it ON.
That state (On or Off) is visible for the human eye when you look at the icon and it is visible by the script where level == 0 or level > 0.
I did not find a way to change levelname of a selector switch with DzVents.
Anyone with an idea?
Dz on Ubuntu VM on DS718+ behind FRITZ!Box.
EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; Sonoff USB-Dongle Plus-E; Zigbee2Mqtt; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; Sonoff USB-Dongle Plus-E; Zigbee2Mqtt; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
- jvdz
- Posts: 2333
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Can a selector levelname be changed with script?
I am on my phone so can't check, but I would open chrome in dev mode(F12), goto the Domoticz webfrontend and edit the switch manually. Then look at the network tab and check the json API call made to perform the change.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 617
- Joined: Sunday 01 November 2015 22:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Twente
- Contact:
Re: Can a selector levelname be changed with script?
Bugs bug me.
-
- Posts: 388
- Joined: Saturday 27 February 2016 0:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Contact:
Re: Can a selector levelname be changed with script?
API called to change selector settings (an probably all other types, when loading proper values) is :
In my case, selector name was "Selector", level 0 was "Off", level 10 was "Level 1", level 20 was "Level 2", level 30 was "Level 3".
Levels are hidden into "options=", which are base 64 encoded.
Decoding gives
Process to make the change is probably intercepting a manual change of this exact device, to get the right parameters, then decoding options, to get the right ones, manually change level(s) names, re-encode them in base 64, and call the API.
You may find here some help if this seems to be complicated
Code: Select all
http://<domoticz IP>/json.htm?addjvalue=0&addjvalue2=0&customimage=0&description=&idx=2254&name=Selector&options=TGV2ZWxOYW1lczpPZmZ8TGV2ZWwgMXxMZXZlbCAyfExldmVsIDM7TGV2ZWxBY3Rpb25zOnx8fDtTZWxlY3RvclN0eWxlOjA7TGV2ZWxPZmZIaWRkZW46ZmFsc2U=¶m=setused&protected=false&strparam1=&strparam2=&switchtype=18&type=command&used=true
Levels are hidden into "options=", which are base 64 encoded.
Decoding
Code: Select all
TGV2ZWxOYW1lczpPZmZ8TGV2ZWwgMXxMZXZlbCAyfExldmVsIDM7TGV2ZWxBY3Rpb25zOnx8fDtTZWxlY3RvclN0eWxlOjA7TGV2ZWxPZmZIaWRkZW46ZmFsc2U
Code: Select all
LevelNames:Off|Level 1|Level 2|Level 3;LevelActions:|||;SelectorStyle:0;LevelOffHidden:false
You may find here some help if this seems to be complicated
-
- Posts: 270
- Joined: Thursday 14 March 2024 10:11
- Target OS: Linux
- Domoticz version: 2025.1
- Location: Netherlands
- Contact:
Re: Can a selector levelname be changed with script?
Great idea. But the result is more complicated then I thought.

It apears that the options are send as an encoded string. See the options part.
Code: Select all
https://MyDomain:MyPort/json.htm?addjvalue=0&addjvalue2=0&customimage=144&description=&idx=1037&name=Vakantiebestemming&options=TGV2ZWxOYW1lczpOTCxCRXxOTCxCRSxMVSxERXxOTCxCRSxMVSxGUnxOTCxCRSxMVSxGUixFU3xOTCxFU3xOTCxERSxDSHxOTCxERSxDSCxJVHxOTCxERSxDSCxBVHxOTCxERSxDSCxBVCxJVDtMZXZlbEFjdGlvbnM6fHx8fHx8fHw7U2VsZWN0b3JTdHlsZToxO0xldmVsT2ZmSGlkZGVuOmZhbHNl¶m=setused&protected=false&strparam1=&strparam2=&switchtype=18&type=command&used=true
Code: Select all
LevelNames:NL,BE|NL,BE,LU,DE|NL,BE,LU,FR|NL,BE,LU,FR,ES|NL,ES|NL,DE,CH|NL,DE,CH,IT|NL,DE,CH,AT|NL,DE,CH,AT,IT;LevelActions:||||||||;SelectorStyle:1;LevelOffHidden:false
Dz on Ubuntu VM on DS718+ behind FRITZ!Box.
EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; Sonoff USB-Dongle Plus-E; Zigbee2Mqtt; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; Sonoff USB-Dongle Plus-E; Zigbee2Mqtt; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
-
- Posts: 270
- Joined: Thursday 14 March 2024 10:11
- Target OS: Linux
- Domoticz version: 2025.1
- Location: Netherlands
- Contact:
Re: Can a selector levelname be changed with script?
I have seen that, but there is no option to change Selector LevelName of a Selector Level.
Dz on Ubuntu VM on DS718+ behind FRITZ!Box.
EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; Sonoff USB-Dongle Plus-E; Zigbee2Mqtt; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; Sonoff USB-Dongle Plus-E; Zigbee2Mqtt; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
-
- Posts: 270
- Joined: Thursday 14 March 2024 10:11
- Target OS: Linux
- Domoticz version: 2025.1
- Location: Netherlands
- Contact:
Re: Can a selector levelname be changed with script?
Yes, Thank you.FlyingDomotic wrote: ↑Friday 16 August 2024 18:49 Levels are hidden into "options=", which are base 64 encoded.
I came to the same conclusion, but a bit risky to edit the option this way.
I will play with it in my test environment, but first I want to look into the database where and how it is stored. That may be easier.
Dz on Ubuntu VM on DS718+ behind FRITZ!Box.
EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; Sonoff USB-Dongle Plus-E; Zigbee2Mqtt; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; Sonoff USB-Dongle Plus-E; Zigbee2Mqtt; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
-
- Posts: 388
- Joined: Saturday 27 February 2016 0:30
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2020.2
- Contact:
Re: Can a selector levelname be changed with script?
Amazingly, data is base64 encoded into database (but good news, options names are in clear text)janpep wrote: ↑Friday 16 August 2024 19:15 It is not my preferred way, but I will also take a look how this is stored in the database, because to encode a new content in this way might lead to problems when manual changes (e.g. added options) have taken place and the script is not adapted to that. Then an sql command may be less risky.

FYI, table is "DeviceStatus", column is "Options". For my previous example, content is:
Code: Select all
LevelActions:fHx8;LevelNames:T2ZmfExldmVsIDF8TGV2ZWwgMnxMZXZlbCAz;LevelOffHidden:ZmFsc2U=;SelectorStyle:MA==
-
- Posts: 270
- Joined: Thursday 14 March 2024 10:11
- Target OS: Linux
- Domoticz version: 2025.1
- Location: Netherlands
- Contact:
Re: Can a selector levelname be changed with script?
You are fastFlyingDomotic wrote: ↑Friday 16 August 2024 19:24 FYI, table is "DeviceStatus", column is "Options". For my previous example, content is:

I was still looking in the wiki and found that 'toBase64(string)' is indeed available in the utils.
I will look into that first and give it a try in my test environment.
Thanks again.
Dz on Ubuntu VM on DS718+ behind FRITZ!Box.
EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; Sonoff USB-Dongle Plus-E; Zigbee2Mqtt; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; Sonoff USB-Dongle Plus-E; Zigbee2Mqtt; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
-
- Posts: 270
- Joined: Thursday 14 March 2024 10:11
- Target OS: Linux
- Domoticz version: 2025.1
- Location: Netherlands
- Contact:
Re: Can a selector levelname be changed with script?
So far so good. It works, but I have to refresh to see the new value.
Code: Select all
if dz.devices(vacation_idx).state == 'Off' then
-- Destination changed, but VacationMode not started but set.
if dz.devices(destination_idx).levelVal > 0 then
--Set the defaultSelectorOpotions in a string.
local defaultSelectorOptions = 'LevelNames:LEVEL0|NL|NL,BE,LU,DE|NL,BE,LU,FR|NL,BE,LU,FR,ES|NL,ES|NL,DE,CH|NL,DE,CH,IT|NL,DE,CH,AT|NL,DE,CH,AT,IT;LevelActions:|||||||||;SelectorStyle:1;LevelOffHidden:false'
-- Get destination from the selected item.
local destination = dz.devices(destination_idx).levelName --get destination from selection.
--Replace LEVEL0 in the string by this selection.
local stringToEncode = string.gsub( defaultSelectorOptions, "LEVEL0", destination )
--Encode the new string.
local encodedString = _u.toBase64( stringToEncode )
--Change the deviceoptions.
dz.executeShellCommand('curl "http://127.0.0.1:portnumber/json.htm?addjvalue=0&addjvalue2=0&customimage=144&description=&idx=' ..destination_idx .. '&name=Vakantiebestemming&options=' .. encodedString .. '¶m=setused&protected=false&strparam1=&strparam2=&switchtype=18&type=command&used=true" ')
-- Select level 0, to that the switch icon is off. It will be turned on when VacationMode starts.
dz.devices(destination_idx).switchSelector(0) --goto level 0
end
end
Dz on Ubuntu VM on DS718+ behind FRITZ!Box.
EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; Sonoff USB-Dongle Plus-E; Zigbee2Mqtt; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
EvoHome; MELCloud; P1 meter; Z-Stick GEN5; Z-Wave-js-ui; Sonoff USB-Dongle Plus-E; Zigbee2Mqtt; MQTT; Greenwave powernodes 1+6; Fibaro switch, plugs, smoke; FRITZ!DECT 200. Scripts listed in profile interests.
Who is online
Users browsing this forum: No registered users and 1 guest