Change Alert Icon set

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
User avatar
athoopen
Posts: 57
Joined: Wednesday 14 December 2022 12:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.2
Location: Netherlands
Contact:

Change Alert Icon set

Post by athoopen »

All,

I created a pollen, migraine and rheumatism device. I use 3 Alert virtual devices for this. This Alert device has 5 levels (0...4) with associated Icons. I like to create a specific icon set for the pollen, migraine and rheumatism devices. I created the icons (0...4) and the general one, created the icon.txt file, put it in a zip and uploaded. However, after I push the Upload button, I get the error: "No icon definition file found."

I created successfully many On/Off icon sets, but what is the syntax for the icon.txt file in case of an "Alert". Currently, it is:

Migraine;Migraine;Migraine;Migraine;Migraine;Migraine

Which was my best guess (name for all the states (0..4) plus the general name).

Anybody knows the syntax of the icon.txt file incase it's not On/Off

TIA!!!
Cheers,
Arjan

Rp3 Using : RFXCom, LaCrosse, KNMI, Remeha, TinyTuya, zigbee and a few others
User avatar
athoopen
Posts: 57
Joined: Wednesday 14 December 2022 12:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.2
Location: Netherlands
Contact:

Re: Change Alert Icon set

Post by athoopen »

I debugged the database and found that the table customimages holds all the custom images you uploaded. It shows that there are only two states, On and OFF. Therefore, I conclude that I cannot create Icon sets which holds more than two states ..... that's a pity.

I'm stuck, I think I will enter a change request, or do you have other options/ideas ...
Cheers,
Arjan

Rp3 Using : RFXCom, LaCrosse, KNMI, Remeha, TinyTuya, zigbee and a few others
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Change Alert Icon set

Post by Jan Jansen »

athoopen wrote: Sunday 14 May 2023 19:28
I created a pollen, migraine and rheumatism device.
I am interested in a pollen device. Will you explain to me how you achieved that? Do you want to share the script used?

Thanks in advance.
User avatar
athoopen
Posts: 57
Joined: Wednesday 14 December 2022 12:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.2
Location: Netherlands
Contact:

Re: Change Alert Icon set

Post by athoopen »

No Problem Jan!!

First create a dummy virtual switch and create there a virutal switch of type "Warning" (Waarschuwing) with an approrpiate name (Hooikoorts???)

On the pi create the follwoing scirpt in /usr/local/bin:

Code: Select all

#
#
# Naslag:
# https://www.domoticz.com/forum/viewtopic.php?t=33518 
# https://pon.fr/dzvents-alerte-pollens/
# https://www.pollens.fr/
#

#
# vars to be changed
#
JSONFile='/tmp/HooikoortsJSONFile.json' # change to full qualified filename
domoticzPort=8080                       # change to your domoticz port number
domoticzIP=127.0.0.1                    # change to domoticz IP (keep 127.0.0.1 if local)

#
# Keep this the same as the trigger of the dzVents script
#
customEvent=JSONHooikoortsFileReady

#
# Vars needed for weeronline.nl
#
CONTINENT=Europa
COUNTRY=Nederland
CITY=Almere
WTFNUMBER=4058927
HOOIKOORTSURL=https://www.weeronline.nl/${CONTINENT}/${COUNTRY}/${CITY}/${WTFNUMBER}/hooikoorts
PAGESOURCEFULL=/tmp/hooikoortsfullpage$$
PAGESOURCE=/tmp/hooikoortspage$$

#############################################
#
# Make no changes below this point!
#
#############################################

#
# get the page
#
lynx -dump ${HOOIKOORTSURL} > ${PAGESOURCEFULL}

#
# Strip all data we don't need
# 
sed -e '1,20d' \
    -e '155,$d' \
    -e 's/^   //' \
    -e 's/^Grote kans op klachten als je gevoelig bent voor: //' \
    -e '/^zo$/d' \
    -e '/^ma$/d' \
    -e '/^di$/d' \
    -e '/^wo$/d' \
    -e '/^do$/d' \
    -e '/^vr$/d' \
    -e '/^za$/d' \
    -e 's/health_hayfever_//' \
    -e 's/Zeer klein/0/' \
    -e 's/Klein/1/' \
    -e 's/Matig/2/' \
    -e 's/Groot/3/' \
    -e 's/Zeer groot/4/' \
    ${PAGESOURCEFULL} > ${PAGESOURCE}

#
# The json  file has a more or less fixed header
#
JSONHEADER="{\"countyName\":\"${CITY}\",\"countyNumber\":\"0\",\"risks\":["

#
# The jsone end can already be computed
#
GENERALRISKLEVEL=$(sed -e '1!d' ${PAGESOURCE})
GENERALRISKTEXT=$(sed -e '2!d' ${PAGESOURCE})
JSONEND="],\"riskLevel\":${GENERALRISKLEVEL}}"

#
# Write the header
#
echo -n ${JSONHEADER} > ${JSONFile}

#
# Process the captured page
#
while read LINE
do
  case "${LINE}" in
	  "Bomen") 
		  # This is the first we process, therefore it does not start with a comma
		  JSONTEXT="{\"pollenName\":\"${LINE}\",\"level\":"
		  read VALUE
		  JSONTEXT2="${VALUE}}" 
		  # read the values for the next 4 days. Currenly not used
		  read DUMMY; read DUMMY ; read DUMMY ; read DUMMY
		  ;;
	  "Grassen en kruiden"| "Ambrosia"| "Grassen"| "Bijvoet"| "Brandnetel"| "Weegbree"| "Rogge"| "Zuring"|\
	  "Els"| "Es"| "Beuk"| "Berk"| "Cipres"| "Iep"| "Hazelaar"| "Eik"| "Populier"| "Tamme Kastanje"| "Wilg") 
		  # This is NOT the first we process, therefore it DOES start with a comma
		  JSONTEXT=",{\"pollenName\":\"${LINE}\",\"level\":"
		  read VALUE
		  JSONTEXT2="${VALUE}}" 
		  # read the values for the next 4 days. Currenly not used
		  read DUMMY; read DUMMY ; read DUMMY ; read DUMMY
		  ;;
          *) echo WTF what is ${LINE} >>/dev/null
		  # There is nothing to output
		  JSONTEXT=""
		  JSONTEXT2=""
		  ;;
  esac

  #
  # Write out the data
  #
  echo -n ${JSONTEXT}${JSONTEXT2} >> ${JSONFile}
done < ${PAGESOURCE}


#
# Write the footer
#
echo -n ${JSONEND} >> ${JSONFile}

#
# Clean up
# 
rm -f ${PAGESOURCEFULL} ${PAGESOURCE}

#
# signal Domoticz (dzVents)
#
#echo curl "http://$domoticzIP:$domoticzPort/json.htm?type=command&param=customevent&event=$customEvent&data=$JSONFile"
curl "http://$domoticzIP:$domoticzPort/json.htm?type=command&param=customevent&event=$customEvent&data=$JSONFile" 2>/dev/null 1>/dev/null

exit 0
Add the following line to the crontab on your pi

Code: Select all

03 * * * * /usr/local/bin/hooikoorts
In Domoticz create a dzEvents (Timer) script). Replace the content of this with the following:

Code: Select all

    local scriptName = 'Hooikoorts' 
    local scriptVersion = '1.0'
    local alert_device = 1921  -- naam of idx van het apparaat (virtueel-> waarschuwing)
    local risques = { 
                    -- "Bomen", -- algemeen, niet gebruiken
                    "Els",
                    "Es",
                    "Beuk",
                    "Berk",
                    "Cipres",
                    "Iep",
                    "Hazelaar",
                    "Eik",
                    "Populier",
                    "Tamme Kastanje",
                    "Wilg",
                    -- "Grassen en kruiden", -- algemeen, niet gebruiken
                    "Ambrosia",
                    "Grassen",
                    "Bijvoet",
                    "Brandnetel",
                    "Weegbree",
                    "Rogge",
                    "Zuring",
                    }

return {
    on = 
    {
        customEvents =
        { 
            'JSONHooikoortsFileReady',
        }
    },
    
    logging = {
                level  = domoticz.LOG_DEBUG, -- options: LOG_INFO, LOG_ERROR, LOG_MODULE_EXEC_INFO
                marker = scriptName..' v'..scriptVersion 
              },

    data = {alertePollens = {initial = {} }, -- Keep a copy of last json just in case
    },        

    execute = function(domoticz, item)

    local function readFile(f)
        local file = io.open (f, 'r') -- open file in read mode
        local data =  file:read('*a')  -- read all
        file:close()
        return data
    end

    -- Read the file 
    local json = domoticz.utils.fromJSON(readFile(item.data))
    
    -- Do we actually have data?
    if #item.data > 0 then
        domoticz.log("We have new accurate data.",domoticz.LOG_ERROR)
        domoticz.data.alertePollens = json
        rt = json
    else
        domoticz.log("Problem with response from Pollens (no data) using data from earlier run",domoticz.LOG_ERROR)
        rt  = domoticz.data.alertePollens                        -- json empty. Get last valid from domoticz.data
        if #rt < 1 then                                         -- No valid data in domoticz.data either
            domoticz.log("No previous data. are Pollens url ok?",domoticz.LOG_ERROR)
            return false
        end
    end

    --Process the json file
    local niveau1, niveau2, niveau3, niveau4, niveau5, text = '', '', '', '', '', ''
    local riskLevel = rt.riskLevel -- this is the general risk level as given by weeronline

    for k, risque in pairs(risques) do
        for k, pollens in pairs(rt.risks) do
            if pollens.pollenName == risque and pollens.level == 4 then niveau5 = niveau5.. " ".. pollens.pollenName.."," end
            if pollens.pollenName == risque and pollens.level == 3 then niveau4 = niveau4.. " ".. pollens.pollenName.."," end
            if pollens.pollenName == risque and pollens.level == 2 then niveau3 = niveau3.. " ".. pollens.pollenName.."," end
            if pollens.pollenName == risque and pollens.level == 1 then niveau2 = niveau2.. " ".. pollens.pollenName.."," end
            if pollens.pollenName == risque and pollens.level == 0 then niveau1 = niveau1.. " ".. pollens.pollenName.."," end
        end
    end

    if          niveau5 ~= '' then text, riskLevel = niveau5, 4
        elseif  niveau4 ~= '' then text, riskLevel = niveau4, 3
        elseif  niveau3 ~= '' then text, riskLevel = niveau3, 2
        elseif  niveau2 ~= '' then text, riskLevel = niveau2, 1
        elseif  niveau1 ~= '' then text, riskLevel = niveau1, 1
        else                       text, riskLevel = "Geen Alert", 0
    end

    text = string.gsub (text, ",$", "") -- remove the "," at the end

    local Kans
    if riskLevel == 4 then Kans="Zeer groot" end
    if riskLevel == 3 then Kans="Groot" end
    if riskLevel == 2 then Kans="Matig" end
    if riskLevel == 1 then Kans="Klein" end
    if riskLevel == 0 then Kans="Zeer klein" end

    MessageText = "Kans " .. Kans .. " bij " .. text
    
    if alert_device ~= nil then
        domoticz.devices(alert_device).updateAlertSensor(riskLevel, MessageText)
    end
end
}
Save it and switch it on :D That should do the trick.

The script gets the info from the weeronline webpage. Creates a json file and sends it to Domoticz . Domoticz picks it up, processes the json file, and updates the virtual sensor. The code is bases on the code which you can find at https://pon.fr/dzvents-alerte-pollens/ I just made it work for weeronline.

Hope you will enjoy it as much as I do (thanks to our French friend).

PS: the implementation for migraine and rheumatism is more or less the same. If interested, let me know, happy to share the code.
Cheers,
Arjan

Rp3 Using : RFXCom, LaCrosse, KNMI, Remeha, TinyTuya, zigbee and a few others
User avatar
waltervl
Posts: 6689
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Change Alert Icon set

Post by waltervl »

Nice work!
Technically it should be possible with one dzvents script that reads the website and updates the Domoticz device(s).
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Change Alert Icon set

Post by Jan Jansen »

Dear Arjan,

Thank you for sharing your script. I'm going to try to get it working on my system.

Regards

Jan
Jan Jansen
Posts: 229
Joined: Wednesday 30 April 2014 20:27
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

Re: Change Alert Icon set

Post by Jan Jansen »

Dear Arjan,

It works, I'm happy!

However, it was necessary to install lynx and supplement the crontab with sudo bash


Regards,

Jan
User avatar
athoopen
Posts: 57
Joined: Wednesday 14 December 2022 12:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.2
Location: Netherlands
Contact:

Re: Change Alert Icon set

Post by athoopen »

Glad it works, enjoy!! Sorry that I didn't mention installing lynx and add a line to the cron.
Cheers,
Arjan

Rp3 Using : RFXCom, LaCrosse, KNMI, Remeha, TinyTuya, zigbee and a few others
User avatar
mvveelen
Posts: 710
Joined: Friday 31 October 2014 10:22
Target OS: NAS (Synology & others)
Domoticz version: Beta
Location: Hoorn, The Netherlands
Contact:

Re: Change Alert Icon set

Post by mvveelen »

waltervl wrote: Thursday 25 May 2023 19:38 Nice work!
Technically it should be possible with one dzvents script that reads the website and updates the Domoticz device(s).
Thanks for sharing the script, although I prefer it to be a dzVents script or something like that. Not really a fan of using another directory like /usr/local/bin instead of the scripts folder and editing a cron separately to run it.
RPi3b+/RFXCOM rfxtrx433E/Shelly/Sonoff Zigbee Gateway/Philips HUE Lights/Atag Zone One/2 SunnyBoy inverters/AirconWithMe/P1 smartmeter/Domoticz latest Beta
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Change Alert Icon set

Post by EdwinK »

Thanks for sharing this. Was looking for something that alerts on pollen. Just hope that someone someday will create it with just one script, instead of going through the shell and crontab.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: Change Alert Icon set

Post by EdwinK »

After this weekend, I'm going to take a look at why it doesn't work for me.


edit: Finally I got it. Had to use sh hooikoorts to get the data.
Last edited by EdwinK on Friday 23 June 2023 23:00, edited 1 time in total.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
Kedi
Posts: 595
Joined: Monday 20 March 2023 14:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Somewhere in NL
Contact:

Re: Change Alert Icon set

Post by Kedi »

Jan Jansen wrote: Thursday 25 May 2023 13:26 I am interested in a pollen device. Will you explain to me how you achieved that? Do you want to share the script used?
There is a nice site with an API which spits out JSON which could be easy processed in dzVents

Code: Select all

 https://docs.ambeedata.com/DeveloperTools/
You can signup and have 100 free requests per day.
There is also Air-quality, Weather and Forest fire to fetch. And even forecast.
Logic will get you from A to B. Imagination will take you everywhere.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest