customicon script Topic is solved
Moderator: leecollings
-
- Posts: 33
- Joined: Wednesday 12 February 2020 6:39
- Target OS: Linux
- Domoticz version: v2022.2
- Location: Czech
- Contact:
customicon script
Can someone help me to make script in LUA which changes icons?
device is general custom sensor with idx 118 and it can have value from 0 to 100.
I want to have for example: if value is > 20 and < 40 than set custom icon 115.
Is it even possible? Iam looking for it for ages but my knowledge of scripts is poor.
Thanks
device is general custom sensor with idx 118 and it can have value from 0 to 100.
I want to have for example: if value is > 20 and < 40 than set custom icon 115.
Is it even possible? Iam looking for it for ages but my knowledge of scripts is poor.
Thanks
DOCKERED v14824,NODE-RED,Tasmotized Sonoffs,Tasmoadmin,zigbee2mqtt,EWPE,REST980,WLED
- bewo
- Posts: 74
- Joined: Monday 13 July 2015 12:27
- Target OS: Linux
- Domoticz version: 2021.1
- Location: Bavaria - Germany
- Contact:
Re: customicon script
Hi jarmoboy,
yes that's possible and no big problem, i've done this often. Just give a few informations more please....
Should the custom sensor show percentage? And the icon? Battery load?
How is the device triggered? (At this trigger the icon should be triggered, too.)
See an example here:
yes that's possible and no big problem, i've done this often. Just give a few informations more please....
Should the custom sensor show percentage? And the icon? Battery load?
How is the device triggered? (At this trigger the icon should be triggered, too.)
See an example here:
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
-
- Posts: 33
- Joined: Wednesday 12 February 2020 6:39
- Target OS: Linux
- Domoticz version: v2022.2
- Location: Czech
- Contact:
Re: customicon script
Exactly, is percentage of battery from robot, data are evaluated from nodered and exactly this icons I have already in domoticz. So I need only example for one case and the other cases (percentage state) I can evaluate and edit myself. I need only the main code to change the icon.
DOCKERED v14824,NODE-RED,Tasmotized Sonoffs,Tasmoadmin,zigbee2mqtt,EWPE,REST980,WLED
- bewo
- Posts: 74
- Joined: Monday 13 July 2015 12:27
- Target OS: Linux
- Domoticz version: 2021.1
- Location: Bavaria - Germany
- Contact:
Re: customicon script
Ok... I use the icons for mixed things. One of this is a vacuum robot. See script details (if needed here): https://www.domoticz.com/forum/viewtopi ... 47#p232887
Here's the piece of code for set different icons:
If there's a question - just ask. 
Here's the piece of code for set different icons:
Code: Select all
-- Batteriestatus (Symbol und Stand) aktualisieren:
batterie_device = Roboter.Name..' Batteriestand'
-- Passends Batterie-Icon festlegen:
if Batterieprozent <= 20 then
batteriesymbol = '102'
elseif Batterieprozent > 20 and Batterieprozent <= 50 then
batteriesymbol = '104'
elseif Batterieprozent > 50 and Batterieprozent <= 90 then
batteriesymbol = '101'
elseif Batterieprozent > 90 then
batteriesymbol = '103'
end
-- Batteriestand schreiben
if Batterieprozent ~= tonumber(otherdevices_svalues[batterie_device]) then
commandArray[#commandArray+1] = {['UpdateDevice'] = otherdevices_idx[batterie_device]..'|0|'..Batterieprozent}
print('Staubsauger-Roboter: '..Roboter.Name..' -> Batteriestand auf '..Batterieprozent..'% aktualisiert.')
os.execute('curl "http://localhost:8077/json.htm?type=setused&idx='..otherdevices_idx[batterie_device]..'&name='..Roboter.Name..'%20Batteriestand&description=&switchtype=0&customimage='..batteriesymbol..'&devoptions=1;%25&used=true"')
end

Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
-
- Posts: 33
- Joined: Wednesday 12 February 2020 6:39
- Target OS: Linux
- Domoticz version: v2022.2
- Location: Czech
- Contact:
Re: customicon script
Hi Bewo,
this topic iam examination whole month and piece of code you gave me I was trying to use yesterday. There is so many variables and things which I don't understand so I wasn't successful at all. BTW. This piece of code you gave me is depended on the other part of lua which work together with this script. After several issues(koalazak plugin made my domoticz crash once a day) I have decided I don't need to control the robot, I want only read the state so I dismissed the plugin and use only nodered to read from API. Honestly, I need something simple and more user friendly. Thank you
this topic iam examination whole month and piece of code you gave me I was trying to use yesterday. There is so many variables and things which I don't understand so I wasn't successful at all. BTW. This piece of code you gave me is depended on the other part of lua which work together with this script. After several issues(koalazak plugin made my domoticz crash once a day) I have decided I don't need to control the robot, I want only read the state so I dismissed the plugin and use only nodered to read from API. Honestly, I need something simple and more user friendly. Thank you
DOCKERED v14824,NODE-RED,Tasmotized Sonoffs,Tasmoadmin,zigbee2mqtt,EWPE,REST980,WLED
- bewo
- Posts: 74
- Joined: Monday 13 July 2015 12:27
- Target OS: Linux
- Domoticz version: 2021.1
- Location: Bavaria - Germany
- Contact:
Re: customicon script
Hi jarmoboy,
you don't have to use any plugin.
You've asked for an piece of code for self construct. There it is (was).
You need a kind of trigger to set the icon. So i thought the right moment is, when a new battery value is reported. There you could integrate the code piece.
But if you don't like to or it's not possible...:
It's even possible to trigger the script once a minute (time trigger), in worst case there's a false icon for an minute.
Would that be ok for you? If yes i would write this few lines of code for you, no problem.
you don't have to use any plugin.

You need a kind of trigger to set the icon. So i thought the right moment is, when a new battery value is reported. There you could integrate the code piece.
But if you don't like to or it's not possible...:
It's even possible to trigger the script once a minute (time trigger), in worst case there's a false icon for an minute.

Would that be ok for you? If yes i would write this few lines of code for you, no problem.
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
-
- Posts: 33
- Joined: Wednesday 12 February 2020 6:39
- Target OS: Linux
- Domoticz version: v2022.2
- Location: Czech
- Contact:
Re: customicon script
If you can.... It would be great
DOCKERED v14824,NODE-RED,Tasmotized Sonoffs,Tasmoadmin,zigbee2mqtt,EWPE,REST980,WLED
- bewo
- Posts: 74
- Joined: Monday 13 July 2015 12:27
- Target OS: Linux
- Domoticz version: 2021.1
- Location: Bavaria - Germany
- Contact:
Re: customicon script
If i don't forget something..... Here it is:
Generate a new Lua-Script, device triggered (So the icon should change immediately.
)
Please change the variables - try out and report.
Generate a new Lua-Script, device triggered (So the icon should change immediately.

Please change the variables - try out and report.

Code: Select all
-- Script to change the icon of a battery device depending it's level
-- Set your devices and variabels here:
Device = 'Example-Name' -- Name of the Sensor-Device
Icon_Nr_RED = '123' -- RED = empty
Icon_Nr_ORANGE = '123' -- ORANGE = low
Icon_Nr_YELLOW = '123' -- YELLOW = ok
Icon_Nr_GREEN = '123' -- GREEN = full
-- Your Domoticz Port in URL (default: 8080)
Domoticz_Port = '8080'
-- Load the domoticz LUA library (Change the path only; default at raspberry is /home/pi/domoticz/scripts/lua/JSON.lua)
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
-- ###############################################################################################
-- Nothing to do after this line... :-)
commandArray = {}
-- Function we need:
function encodeURI(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
--------------------------------------------------------------------------
BatteryLevel = tonumber(otherdevices_svalues[Device])
if devicechanged[Device] then
-- Look for the icon which is used in the moment:
json_collect = assert(io.popen('curl "http://localhost:'..Domoticz_Port..'/json.htm?type=devices&rid='..otherdevices_idx[Device]..'"'))
json_collect_data = json_collect:read('*all')
json_collect:close()
Icon_Number = json:decode(json_collect_data).result[1]["CustomImage"]
Icon = tostring(Icon_Number)
-- Choose the correct icon
if BatteryLevel <= 20 then
battery_icon = Icon_Nr_RED
elseif BatteryLevel > 20 and BatteryLevel <= 50 then
battery_icon = Icon_Nr_ORANGE
elseif BatteryLevel > 50 and BatteryLevel <= 80 then
battery_icon = Icon_Nr_YELLOW
elseif BatteryLevel > 80 and BatteryLevel <= 100 then
battery_icon = Icon_Nr_GREEN
end
-- Update the icon if not the correct one is active:
if battery_icon ~= Icon then
os.execute('curl "http://localhost:'..Domoticz_Port..'/json.htm?type=setused&idx='..otherdevices_idx[Device]..'&name='..encodeURI(Device)..'&description=&switchtype=0&customimage='..battery_icon..'&devoptions=1;%25&used=true"')
print('Icon of the device '..Device..' was updated.')
end
end
return commandArray
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
-
- Posts: 33
- Joined: Wednesday 12 February 2020 6:39
- Target OS: Linux
- Domoticz version: v2022.2
- Location: Czech
- Contact:
Re: customicon script
2020-04-16 22:31:00.405 Error: EventSystem: in ikony roza: [string "-- Script to change the icon of a battery dev..."]:36: attempt to index a nil value (global 'devicechanged')
this line is causing problems:
if devicechanged[Device] then
This was a fail with time trigered LUA....my fault
When i changed it to device trigered it says: 2020-04-16 22:45:14.330 Error: EventSystem: in ikony roza: /home/pi/domoticz/scripts/lua/JSON.lua:808: HTML passed to JSON:decode(): <html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
my complete code is:
this line is causing problems:
if devicechanged[Device] then
This was a fail with time trigered LUA....my fault
When i changed it to device trigered it says: 2020-04-16 22:45:14.330 Error: EventSystem: in ikony roza: /home/pi/domoticz/scripts/lua/JSON.lua:808: HTML passed to JSON:decode(): <html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
my complete code is:
Code: Select all
-- Script to change the icon of a battery device depending it's level
-- Set your devices and variabels here:
Device = 'Roza baterka' -- Name of the Sensor-Device
Icon_Nr_RED = '114' -- RED = empty
Icon_Nr_ORANGE = '116' -- ORANGE = low
Icon_Nr_YELLOW = '117' -- YELLOW = ok
Icon_Nr_GREEN = '115' -- GREEN = full
-- Your Domoticz Port in URL (default: 8080)
Domoticz_Port = '8084'
-- Load the domoticz LUA library (Change the path only; default at raspberry is /home/pi/domoticz/scripts/lua/JSON.lua)
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
-- ###############################################################################################
-- Nothing to do after this line... :-)
commandArray = {}
-- Function we need:
function encodeURI(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
--------------------------------------------------------------------------
BatteryLevel = tonumber(otherdevices_svalues[Device])
if devicechanged[Device] then
-- Look for the icon which is used in the moment:
json_collect = assert(io.popen('curl "http://localhost:'..Domoticz_Port..'/json.htm?type=devices&rid='..otherdevices_idx[Device]..'"'))
json_collect_data = json_collect:read('*all')
json_collect:close()
Icon_Number = json:decode(json_collect_data).result[1]["CustomImage"]
Icon = tostring(Icon_Number)
-- Choose the correct icon
if BatteryLevel <= 20 then
battery_icon = Icon_Nr_RED
elseif BatteryLevel > 20 and BatteryLevel <= 50 then
battery_icon = Icon_Nr_ORANGE
elseif BatteryLevel > 50 and BatteryLevel <= 80 then
battery_icon = Icon_Nr_YELLOW
elseif BatteryLevel > 80 and BatteryLevel <= 100 then
battery_icon = Icon_Nr_GREEN
end
-- Update the icon if not the correct one is active:
if battery_icon ~= Icon then
os.execute('curl "http://localhost:'..Domoticz_Port..'/json.htm?type=setused&idx='..otherdevices_idx[Device]..'&name='..encodeURI(Device)..'&description=&switchtype=0&customimage='..battery_icon..'&devoptions=1;%25&used=true"')
print('Icon of the device '..Device..' was updated.')
end
end
return commandArray
Last edited by jarmoboy on Tuesday 21 April 2020 12:32, edited 2 times in total.
DOCKERED v14824,NODE-RED,Tasmotized Sonoffs,Tasmoadmin,zigbee2mqtt,EWPE,REST980,WLED
- bewo
- Posts: 74
- Joined: Monday 13 July 2015 12:27
- Target OS: Linux
- Domoticz version: 2021.1
- Location: Bavaria - Germany
- Contact:
Re: customicon script
Did you set up as device triggered?
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
-
- Posts: 33
- Joined: Wednesday 12 February 2020 6:39
- Target OS: Linux
- Domoticz version: v2022.2
- Location: Czech
- Contact:
Re: customicon script
Please read again I made edit. Thx
DOCKERED v14824,NODE-RED,Tasmotized Sonoffs,Tasmoadmin,zigbee2mqtt,EWPE,REST980,WLED
- bewo
- Posts: 74
- Joined: Monday 13 July 2015 12:27
- Target OS: Linux
- Domoticz version: 2021.1
- Location: Bavaria - Germany
- Contact:
Re: customicon script
A sorry my bad... I've didn't seen...
Make sure that localhost has the rights to collect the json.
Therefore you have to set localhost (127.0.0.1) in your settings under local network:

Make sure that localhost has the rights to collect the json.
Therefore you have to set localhost (127.0.0.1) in your settings under local network:
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
-
- Posts: 33
- Joined: Wednesday 12 February 2020 6:39
- Target OS: Linux
- Domoticz version: v2022.2
- Location: Czech
- Contact:
Re: customicon script
I have add it but still says the same...
DOCKERED v14824,NODE-RED,Tasmotized Sonoffs,Tasmoadmin,zigbee2mqtt,EWPE,REST980,WLED
-
- Posts: 33
- Joined: Wednesday 12 February 2020 6:39
- Target OS: Linux
- Domoticz version: v2022.2
- Location: Czech
- Contact:
Re: customicon script
Is there something i can write to command line to find out why is unauthorized?
THX
THX
DOCKERED v14824,NODE-RED,Tasmotized Sonoffs,Tasmoadmin,zigbee2mqtt,EWPE,REST980,WLED
- bewo
- Posts: 74
- Joined: Monday 13 July 2015 12:27
- Target OS: Linux
- Domoticz version: 2021.1
- Location: Bavaria - Germany
- Contact:
Re: customicon script
Sorry the delay... 
Did you restart Domoticz after add 127.0.0.1 in the settings? Sometimes there some network issues...
Yes, you can test this in CLI. In your case type:
And you should get some information about domoticz version.

Did you restart Domoticz after add 127.0.0.1 in the settings? Sometimes there some network issues...

Yes, you can test this in CLI. In your case type:
Code: Select all
curl "http://127.0.0.1:8084/json.htm?type=command¶m=getversion"
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
-
- Posts: 33
- Joined: Wednesday 12 February 2020 6:39
- Target OS: Linux
- Domoticz version: v2022.2
- Location: Czech
- Contact:
Re: customicon script
HI,
No preblem, i've got info about version, so it works.
No preblem, i've got info about version, so it works.
DOCKERED v14824,NODE-RED,Tasmotized Sonoffs,Tasmoadmin,zigbee2mqtt,EWPE,REST980,WLED
- bewo
- Posts: 74
- Joined: Monday 13 July 2015 12:27
- Target OS: Linux
- Domoticz version: 2021.1
- Location: Bavaria - Germany
- Contact:
Re: customicon script
And the script still doesn‘t work?
If not, maybe your network is not well configured.
Please change in my script „localhost“ to „127.0.0.1“. It‘s near under „Look for the icon which is used in the moment“

If not, maybe your network is not well configured.
Please change in my script „localhost“ to „127.0.0.1“. It‘s near under „Look for the icon which is used in the moment“

Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: customicon script
Are you aware that you could use dzVents and apply the method setIcon(iconNumber) ?
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: 33
- Joined: Wednesday 12 February 2020 6:39
- Target OS: Linux
- Domoticz version: v2022.2
- Location: Czech
- Contact:
Re: customicon script
Tadaaaaa, it works,
Problem was "localhost". When i replace it with 127.0.0.1 everything works.
Thanky you Bewo for you magical skills.
So for further use and others iam including working code:
Problem was "localhost". When i replace it with 127.0.0.1 everything works.
Thanky you Bewo for you magical skills.
So for further use and others iam including working code:
Code: Select all
-- Script to change the icon of a battery device depending it's level
-- Set your devices and variabels here:
Device = 'Roza baterka' -- Name of the Sensor-Device
Icon_Nr_RED = '114' -- RED = empty
Icon_Nr_ORANGE = '116' -- ORANGE = low
Icon_Nr_YELLOW = '117' -- YELLOW = ok
Icon_Nr_GREEN = '115' -- GREEN = full
-- Your Domoticz Port in URL (default: 8080)
Domoticz_Port = '8084'
-- Load the domoticz LUA library (Change the path only; default at raspberry is /home/pi/domoticz/scripts/lua/JSON.lua)
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
-- ###############################################################################################
-- Nothing to do after this line... :-)
commandArray = {}
-- Function we need:
function encodeURI(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
--------------------------------------------------------------------------
BatteryLevel = tonumber(otherdevices_svalues[Device])
if devicechanged[Device] then
-- Look for the icon which is used in the moment:
json_collect = assert(io.popen('curl "http://127.0.0.1:'..Domoticz_Port..'/json.htm?type=devices&rid='..otherdevices_idx[Device]..'"'))
json_collect_data = json_collect:read('*all')
json_collect:close()
Icon_Number = json:decode(json_collect_data).result[1]["CustomImage"]
Icon = tostring(Icon_Number)
-- Choose the correct icon
if BatteryLevel <= 20 then
battery_icon = Icon_Nr_RED
elseif BatteryLevel > 20 and BatteryLevel <= 50 then
battery_icon = Icon_Nr_ORANGE
elseif BatteryLevel > 50 and BatteryLevel <= 80 then
battery_icon = Icon_Nr_YELLOW
elseif BatteryLevel > 80 and BatteryLevel <= 100 then
battery_icon = Icon_Nr_GREEN
end
-- Update the icon if not the correct one is active:
if battery_icon ~= Icon then
os.execute('curl "http://127.0.0.1:'..Domoticz_Port..'/json.htm?type=setused&idx='..otherdevices_idx[Device]..'&name='..encodeURI(Device)..'&description=&switchtype=0&customimage='..battery_icon..'&devoptions=1;%25&used=true"')
print('Icon of the device '..Device..' was updated.')
print('Correct number of icon is '..battery_icon..'')
end
end
return commandArray
DOCKERED v14824,NODE-RED,Tasmotized Sonoffs,Tasmoadmin,zigbee2mqtt,EWPE,REST980,WLED
-
- Posts: 33
- Joined: Wednesday 12 February 2020 6:39
- Target OS: Linux
- Domoticz version: v2022.2
- Location: Czech
- Contact:
Re: customicon script
one more thing, iam perfectionist...
ive tried myself to use the code also for text device, ive checked few step with "print" to check if it uses right icon it says it does but it doesnt.
What is wrong there?
ive tried myself to use the code also for text device, ive checked few step with "print" to check if it uses right icon it says it does but it doesnt.
What is wrong there?
Code: Select all
-- Script to change the icon of a text device depending it's announcement
-- Set your devices and variabels here:
Device = 'Roza stav kose' -- Name of the Sensor-Device
Icon_Nr_RED = '121' -- RED
Icon_Nr_ORANGE = '120' -- ORANGE
Icon_Nr_GREEN = '119' -- GREEN
-- Your Domoticz Port in URL (default: 8080)
Domoticz_Port = '8084'
-- Load the domoticz LUA library (Change the path only; default at raspberry is /home/pi/domoticz/scripts/lua/JSON.lua)
json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")()
-- ###############################################################################################
-- Nothing to do after this line... :-)
commandArray = {}
-- Function we need:
function encodeURI(str)
if (str) then
str = string.gsub (str, "\n", "\r\n")
str = string.gsub (str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
--------------------------------------------------------------------------
BatteryLevel = tostring(otherdevices_svalues[Device])
if devicechanged[Device] then
-- Look for the icon which is used in the moment:
json_collect = assert(io.popen('curl "http://127.0.0.1:'..Domoticz_Port..'/json.htm?type=devices&rid='..otherdevices_idx[Device]..'"'))
json_collect_data = json_collect:read('*all')
json_collect:close()
Icon_Number = json:decode(json_collect_data).result[1]["CustomImage"]
Icon = tostring(Icon_Number)
print('ted tam je ikona pro kos '..Icon..'')
-- Choose the correct icon
if BatteryLevel == 'Kos je v poradku' then
battery_icon = Icon_Nr_GREEN
elseif BatteryLevel == 'Roza nema kos!'then
battery_icon = Icon_Nr_RED
elseif BatteryLevel == 'Roza ma plny kos!'then
battery_icon = Icon_Nr_YELLOW
end
-- Update the icon if not the correct one is active:
if battery_icon ~= Icon then
os.execute('curl "http://127.0.0.1:'..Domoticz_Port..'/json.htm?type=setused&idx='..otherdevices_idx[Device]..'&name='..encodeURI(Device)..'&description=&switchtype=0&customimage='..battery_icon..'&devoptions=1;%25&used=true"')
print('Icon of the device '..Device..' was updated.')
print('Spravne cislo je '..battery_icon..'')
end
end
return commandArray
DOCKERED v14824,NODE-RED,Tasmotized Sonoffs,Tasmoadmin,zigbee2mqtt,EWPE,REST980,WLED
Who is online
Users browsing this forum: No registered users and 1 guest