how to change switch-icon on the fly
Moderators: leecollings, remb0
-
- Posts: 347
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.3
- Location: Netherlands
- Contact:
how to change switch-icon on the fly
I am controlling a light in the garden via an url sent from Domoticz to arduino. e.g.:
http://192.168.2.17/LED=ON and http://192.168.2.17/LED=OFF
Up to now the switch icon immediately turns into yellow-color but I only want to change the switch icon if it's sure the light is on. (Same as with Zwave switches.)
Communication in two ways works already fine for me but it's unclear how to change an icon control.
e.g. set a var named 'LightIsOn' [1=on; 0 I=off]. depending on status of that var the icon should change.
So if the light is on Arduino (in the garden) sents:Domoticz_IP:8080//json.htm?type=command¶m=updateuservariable&vname=USERVARIABLENAME&vtype=USERVARIABLETYPE
&vvalue=USERVARIABLEVALUE. A contact of a relay which is connected across the lamp informs Arduino : light is on.
Basically same procedure will be applied later on in the project to show whether or not a gardendoor has been locked (by activation of inductive limit switch). In that case only comm from Arduino towards Domoticz.
Any suggestion?
TIA
-Bart
http://192.168.2.17/LED=ON and http://192.168.2.17/LED=OFF
Up to now the switch icon immediately turns into yellow-color but I only want to change the switch icon if it's sure the light is on. (Same as with Zwave switches.)
Communication in two ways works already fine for me but it's unclear how to change an icon control.
e.g. set a var named 'LightIsOn' [1=on; 0 I=off]. depending on status of that var the icon should change.
So if the light is on Arduino (in the garden) sents:Domoticz_IP:8080//json.htm?type=command¶m=updateuservariable&vname=USERVARIABLENAME&vtype=USERVARIABLETYPE
&vvalue=USERVARIABLEVALUE. A contact of a relay which is connected across the lamp informs Arduino : light is on.
Basically same procedure will be applied later on in the project to show whether or not a gardendoor has been locked (by activation of inductive limit switch). In that case only comm from Arduino towards Domoticz.
Any suggestion?
TIA
-Bart
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
-
- Posts: 347
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.3
- Location: Netherlands
- Contact:
Re: how to change switch-icon on the fly
Hi.
Over 2 years since I asked about changing icons on the fly but never got a suggestion.
Maybe now?
TIA
-Bart
Over 2 years since I asked about changing icons on the fly but never got a suggestion.
Maybe now?
TIA
-Bart
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: how to change switch-icon on the fly
Code: Select all
http://<domoticz ip: domoticz port>/json.htm?type=setused&used=true&name=<name>&description=<description>&idx=<idx>&switchtype=<switchType>&customimage=<iconNumber>
Code: Select all
domoticz.devices('device name').setIcon('icon number')
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 113
- Joined: Sunday 14 July 2013 22:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: NL
- Contact:
Re: how to change switch-icon on the fly
Hi Waaren,waaren wrote: ↑Monday 04 January 2021 0:26or in a dzVents script:Code: Select all
http://<domoticz ip: domoticz port>/json.htm?type=setused&used=true&name=<name>&description=<description>&idx=<idx>&switchtype=<switchType>&customimage=<iconNumber>
Code: Select all
domoticz.devices('device name').setIcon('icon number')
Is it possible with this dzVents command to change the Icon 'text' at a custom dummy created device?
BR, Jeroen
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: how to change switch-icon on the fly
Yes but you need to be on the Beta version build >= 12750.
Please note tat the iconchange will only be visible when you reopen the screen or after you manually refresh [(ctrl] r in Chrome) or switch back and forth via another screen.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 113
- Joined: Sunday 14 July 2013 22:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: NL
- Contact:
Re: how to change switch-icon on the fly
Great!
Ehh @waaren, how do I find the Icon number? I've got the name but not a number
BR,
Jeroen
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: how to change switch-icon on the fly
Maybe there are better / easier ways but I do
Code: Select all
cd <domoticz dir>
sudo sqlite3 -header domoticz.db " select id+100 id ,name from customimages"
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 347
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.3
- Location: Netherlands
- Contact:
Re: how to change switch-icon on the fly
Hi Waaren,
Thanks for this info.
I played a bit but for me it seems to academic (syntax).
Would it be possible that you give kind of practic example?
TIA
-Bart
Thanks for this info.
I played a bit but for me it seems to academic (syntax).
Would it be possible that you give kind of practic example?
TIA
-Bart
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: how to change switch-icon on the fly
Sure, if you have a dzVents script in where you want to use the setIcon() method and an icon number you uploaded, I will show you how it can be done.
I use it in below dzVents script but because of some of the other techniques used in that code I don't know if it will help or confuse you more.
Code: Select all
--[[
dz Moonphase script
Version 1.03
dzVents >= 3.0.1)
More info https://github.com/JoopIdema/dz-MoonPhases and dz forum https://www.domoticz.com/forum/search.php?keywords=Moonphase
]]--
local scriptVar = 'moonScript'
local api_key = 'Obscured'
local town = 'Rotterdam'
return
{
on =
{
timer =
{
'at 00:11',
},
httpResponses =
{
scriptVar,
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = scriptVar,
},
execute = function(dz, item)
if not( item.isHTTPResponse ) then
dz.openURL(
{
url = 'https://weather.ls.hereapi.com/weather/1.0/report.json?apiKey=' .. api_key .. '&product=forecast_astronomy&name=' .. town ,
method = 'GET',
callback = scriptVar,
})
return
end
local firstIcon = 100
local moonPhaseIDX = 164
local function make24hTime(myTime)
local pattern = "(%d+)%:(%d+)(%w*)"
local hour, minute, meridiem = myTime:match(pattern)
return string.format("%02d:%02d", ( meridiem == 'PM' and ( hour or 0 ) + 12 or ( hour or 0 )), minute or 0)
end
local function makeMoonPhase(phase)
local moonPhaseTable =
{
['new moon'] = { 1, 'Nieuwe maan'},
['waxing crescent'] = { 2, 'Wassende halve maan'},
['first quarter'] = { 3, 'Eerste kwartier'},
['waxing gibbous'] = { 4, 'Wassende maan'},
['full moon'] = { 5, 'Volle maan'},
['waning gibbous'] = { 6, 'Afnemende maan'},
['last quarter'] = { 7, 'Laatste kwartier'},
['waning crescent'] = { 8, 'Afnemende halve maan'},
}
return moonPhaseTable[phase:lower()][1] + firstIcon, moonPhaseTable[phase:lower()][2]
end
if item.ok and item.isJSON then
local moonPhase = dz.devices('MoonPhase')
-- dz.utils.dumpTable(item.json)
local rt = item.json.astronomy.astronomy[1]
local moonPhasePercentage = math.abs(rt.moonPhase * 100)
local moonPhaseIconNumber, moonPhaseName= makeMoonPhase(rt.moonPhaseDesc)
local currentIcon = math.tointeger((moonPhase.icon):gsub('MoonPhases',''):sub(1,1) + firstIcon)
dz.devices('MoonPhaseDesc').updateText(moonPhaseName .. '\nmoonrise: ' .. make24hTime(rt.moonrise) .. '\nmoonset: ' .. make24hTime(rt.moonset))
dz.devices('MoonPhase').updateCustomSensor(moonPhasePercentage)
if currentIcon ~= moonPhaseIconNumber then dz.devices('MoonPhase').setIcon(moonPhaseIconNumber) end
dz.log('moonPhasePercentage: ' .. moonPhasePercentage, dz.LOG_DEBUG)
dz.log('moonPhaseIcon: ' .. dz.devices('MoonPhase').icon, dz.LOG_DEBUG)
else
dz.log('There was a problem handling the request', dz.LOG_ERROR)
dz.log(item, dz.LOG_ERROR)
end
end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 347
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.3
- Location: Netherlands
- Contact:
Re: how to change switch-icon on the fly
Dear Waaren, I hoped you might make available an example using the http:/domoticz-ip,domoticz-port etc syntax.
That way It would be possible to change an icon from a device such as esp-easy as well other network devices too. Can you give me a hand on this?
Thanks
Bart
That way It would be possible to change an icon from a device such as esp-easy as well other network devices too. Can you give me a hand on this?
Thanks
Bart
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
- waltervl
- Posts: 5148
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: how to change switch-icon on the fly
Why not make a virtual switch instead of a text device? Then you have an on/off icon. If you want to make a custom icon garden lights then you can do that too. No need to do a complicated thing with scripts, just update the device status on/off with the domotica API/json from Arduino.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: how to change switch-icon on the fly
I already did earlier in this topic.BartSr wrote: ↑Saturday 16 January 2021 16:22 Dear Waaren, I hoped you might make available an example using the http:/domoticz-ip,domoticz-port etc syntax.
That way It would be possible to change an icon from a device such as esp-easy as well other network devices too. Can you give me a hand on this?
in this post
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 347
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.3
- Location: Netherlands
- Contact:
Re: how to change switch-icon on the fly
Dear Waaren. That one I referred to when I spoke about "academic" .
I know once you know how to interprete the syntax it's pretty easy. But the otherway around it might, as for me, have an academic look....
I know once you know how to interprete the syntax it's pretty easy. But the otherway around it might, as for me, have an academic look....
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: how to change switch-icon on the fly
Code: Select all
http://<domoticz ip: domoticz port>/json.htm?type=setused&used=true&name=<name>&description=<description>&idx=<idx>&switchtype=<switchType>&customimage=<iconNumber>
Code: Select all
http://192.168.192.115:8084/json.htm?type=setused&used=true&name=MoonPhase&description=&idx=164&switchtype=0&customimage=102
the idx of this Sensor = 164 and is a Generic device type (0)
The customImage number can be found
using
Code: Select all
cd <domoticz dir>
sudo sqlite3 -header domoticz.db " select id+100 id ,name from customimages"
Code: Select all
cd /opt/domoticz
sudo sqlite3 -header domoticz.db " select id+100 id ,name from customimages"
- Spoiler: show
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 347
- Joined: Sunday 03 July 2016 16:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2024.3
- Location: Netherlands
- Contact:
Re: how to change switch-icon on the fly
Waaren, thanks a lot. This makes sense to me. Going to try and will of course revert with results.
-Bart
-Bart
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
Arduino
KAKU
RfxCom
Zwave
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 espeasy
MQTT
Re: how to change switch-icon on the fly
Code: Select all
http://<domoticz ip: domoticz port>/json.htm?type=setused&used=true&name=<name>&description=<description>&idx=<idx>&switchtype=<switchType>&customimage=<iconNumber>
but I can't figure out how to actually change the icons to on or off. If I write down the numbers assigned to the icons, the group of icons (where there are two icons on and off) has only one number...
Who is online
Users browsing this forum: No registered users and 0 guests