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¶m=customevent&event=$customEvent&data=$JSONFile"
curl "http://$domoticzIP:$domoticzPort/json.htm?type=command¶m=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

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.