Thanks you, but it don’t work.
when I try
String DWD_UVI_totay “UV-Index Heute [%s]” {http="<[cacheDWD_UVI:600000:JSONPATH($.content[?(@.city==Hamburg)].forecast.today)]" }
I get nearly the whole JSON
Any Idea?
Thanks you, but it don’t work.
when I try
String DWD_UVI_totay “UV-Index Heute [%s]” {http="<[cacheDWD_UVI:600000:JSONPATH($.content[?(@.city==Hamburg)].forecast.today)]" }
I get nearly the whole JSON
Any Idea?
There should be quotes in the JSONPATH. Probably they have to be escaped:
Number DWD_UVI_totay " UV-Index Heute" {http="<[cacheDWD_UVI:600000:JSONPATH($.content[?(@.city==\"Hamburg\")].forecast.today)]" }
This don‘t work, too. I change forcast to forecast, no effect.
Hi.
Since yesterday my pollen values are not working without changing anything. Only update over openhabian-config.
Get the message “don’t find null in pollen.map.”
Will check the complet message, but are there any ideas?
Greetings,
Markus
Ups, typo… changed this in original post…
Ok, But this don‘t work, too. Any Ideas?
So, I try it with the tool from jsonpath.com.
According to this tool, I get the right value with the path
$.content.[?(@.city==“Hamburg”)].forecast.today
BUT when I try to integrate it to an item like this
Number DWD_UVI_totay " UV-Index Heute [%s]" {http="<[cacheDWD_UVI:600000:JSONPATH($.content.[?(@.city=="Hamburg")].forecast.today)]" }
I get an error: dismatched input ‘Hamburg’ expecting ‘}’
I don’t know why. Can anybody help?
I find the answer. it should be single quote and not double quote
Number DWD_UVI_totay " UV-Index Heute [%s]" {http="<[cacheDWD_UVI:600000:JSONPATH($.content.[?(@.city=='Hamburg')].forecast.today)]" }
now it works
nice icons.
Could you please share it?
Unfortunately, I grabbed them from an online service (and built the svg version through CorelDraw), so I don’t have the copyright.
I try to get also the “Biowetter”. It’s more difficult.
Here is a working Item-String
String DWD_Biowetter_Leistung {http="<[cacheDWD_biowetter:600000:JSONPATH($..[?(@.id=='A')].today_afternoon.effect..subeffect.[?(@.name=='psychisch-geistige Leistungsfähigkeit')].value )]"}
Hi, I need pollen data the DWD does not deliver (Oak and maybe beech (Eiche und Buche)). That’s why I use the data from Hexal, they provide xml files. I think the “clean” way would be via xslt, but I did not get that to work
That’s why I wrote a small shell script that updates my 2 items via REST api. Maybe it helps anybody…
# download xml
rm /etc/openhab2/html/pollen.xml
wget -q -O /etc/openhab2/html/pollen.xml "http://www.allergie.hexal.de/pollenflug/xml-interface-neu/pollen_de_7tage.php?plz=12345"
if [ ! -s /etc/openhab2/html/pollen.xml ]; then
echo "xml-Datei ist leer. Vermutlich kein Internet. Ich geh wieder schlafen..."
exit
fi
#
# Eiche heute
value_old=$(curl -s "http://openhabianpi:8080/rest/items/Pollen_today/state")
value=$(</etc/openhab2/html/pollen.xml awk -F'tag="0"' '{print $2}' | awk -F'name="Eiche" belastung="' '{print $2}' | awk -F'"' '{print $1}')
if [ -n "$value" ]; then # check if value was found
if [ "$value" != "$value_old" ]; then # check if value changed
curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/Pollen_today/state"
fi
fi
# Eiche morgen
value_old=$(curl -s "http://openhabianpi:8080/rest/items/Pollen_tomorrow/state")
value=$(</etc/openhab2/html/pollen.xml awk -F'tag="1"' '{print $2}' | awk -F'name="Eiche" belastung="' '{print $2}' | awk -F'"' '{print $1}')
if [ -n "$value" ]; then # check if value was found
if [ "$value" != "$value_old" ]; then # check if value changed
curl -s -X PUT --header "Content-Type: text/plain" --header "Accept: application/json" -d "$value" "http://openhabianpi:8080/rest/items/Pollen_tomorrow/state"
fi
fi
Or, maybe, someone has the working xslt solution
“Just for fun” I played with that xslt stuff. If someone wants, here is an xslt file for “Hexal - Pollen - Eiche - heute” (Hexal Pollen Oak today) - but it’s easy to adjust it for other pollen (Replace Eiche by another delivered pollen name) or for tomorrow (replace 0 by 1).
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="xml" encoding="UTF-8" omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:value-of select="datasets/pollendaten/pollenbelastungen[@tag='0']/pollen[@name='Eiche']/@belastung" />
</xsl:template>
</xsl:stylesheet>
And the item:
String Pollen_test "Pollen Test [%s]" {http="<[http://www.allergie.hexal.de/pollenflug/xml-interface-neu/pollen_de_7tage.php?plz=12345:300000:XSLT(pollen_hexal_eiche_heute.xsl)]"}
I myself will stick to the script way, because I have more possibilities for error handling (e.g. my bad internet connection - should get better with the new house
)
This rule for converting the last update-time to a datetime format is not working. I always get an error:
2018-09-04 11:55:46.881 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Pollen datetime': 'subString' is not a member of 'java.lang.String'; line 5, column 41, length 48
Can you post your tule, please and highlight line 5
Thanks
Only this lines are in the rule-file:
rule "Pollen datetime"
when
Item DWD_Pollen_last_update changed
then
PollenLastUpdateDateTime.postUpdate(DWD_Pollen_last_update.toString.subString(0, 16))
end
Items:
String DWD_Pollen_last_update "letzte Aktualisierung [%s]" <time> {http="<[cacheDWD_Pollen:600000:JSONPATH($.last_update)]" }
DateTime PollenLastUpdateDateTime "letzte Aktualisierung [%s]" <time>
This is my error output from scvode:
{
"resource": "/w:/rules/pollen.rules",
"owner": "_generated_diagnostic_collection_name_#0",
"code": "org.eclipse.xtext.diagnostics.Diagnostic.Linking",
"severity": 8,
"message": "The method subString(int, int) is undefined for the type String",
"startLineNumber": 5,
"startColumn": 73,
"endLineNumber": 5,
"endColumn": 82
}
Is there a way to save the conversion from string to datetime into a variable and then change the datetime variable to a better readable format (for german users)? I use this code in another rule to do this:
var SimpleDateFormat df = new SimpleDateFormat( "dd.MM., HH:mm" )
var String timestamp = df.format( new Date() )
postUpdate(exampleItem, timestamp)
substring
no capitals
PollenLastUpdateDateTime.postUpdate(DWD_Pollen_last_update.toString.substring(0, 16))
Ok, maybe you can edit your original rule in this thread too.
Done