Graph question
Moderators: leecollings, htilburgs, robgeerts
-
- Posts: 153
- Joined: Tuesday 28 June 2016 16:38
- Target OS: Windows
- Domoticz version: Beta
- Location: Amersfoort NL
- Contact:
Graph question
Hi,
I have a Custom Sensor in Domoticz that counts the infected corona people. In Domoticz this works fine. In the Dashticz i added it as a graph but the counter in the upper left corner is always 0,0 and is not updated. Any clue?
I have a Custom Sensor in Domoticz that counts the infected corona people. In Domoticz this works fine. In the Dashticz i added it as a graph but the counter in the upper left corner is always 0,0 and is not updated. Any clue?
-
- Posts: 17
- Joined: Monday 25 April 2016 10:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Graph question
Can't answer your question, but how did you set up this sensor in Domoticz?
-
- Posts: 153
- Joined: Tuesday 28 June 2016 16:38
- Target OS: Windows
- Domoticz version: Beta
- Location: Amersfoort NL
- Contact:
Re: Graph question
Getting the data from: https://coronavirus-19-api.herokuapp.com/all
This will give you: {"cases":279338,"deaths":11587,"recovered":92906}
Ad some LUA code to parse the values and update a custom sensor with the values, like this:
I do this on Windows btw.
If you want the numbers from a specific country, you can do vor example:
https://coronavirus-19-api.herokuapp.co ... etherlands
I run this scheduled on a windows machine and output it to a .txt file in the domoticz folder.
This will give you: {"cases":279338,"deaths":11587,"recovered":92906}
Ad some LUA code to parse the values and update a custom sensor with the values, like this:
Code: Select all
Debug = "On"
if Debug == "On" then
print "LUA-Corona Executed"
end
JSON = (loadfile "C:\\Program Files (x86)\\Domoticz\\scripts\\lua\\JSON.lua")()
function docorona(filename, ctype1, ctype2, ctype3)
file = io.open(filename, "r")
json_text = file:read()
file:close()
corona = JSON:decode(json_text)
commandArray[1]={['UpdateDevice']=ctype1..'|0|'..corona.cases}
commandArray[2]={['UpdateDevice']=ctype2..'|0|'..corona.deaths}
commandArray[3]={['UpdateDevice']=ctype3..'|0|'..corona.recovered}
if Debug == "On" then
print (tostring "Cases=" ..corona.cases.. " Deaths=" ..corona.deaths.. " recovered=" ..corona.recovered)
end
end
function docoronaNL(filename, cnltype1, cnltype2, cnltype3)
file = io.open(filename, "r")
json_text = file:read()
file:close()
coronanl = JSON:decode(json_text)
if Debug == "On" then
print (tostring "CasesNL=" ..coronanl.cases.. " DeathsNL=" ..coronanl.deaths.. " recoveredNL=" ..coronanl.recovered)
end
end
-- run the function and update the corresponding IDX
docorona("corona.txt", 927, 925, 926)
docoronaNL("coronaNL.txt", 1927, 1925, 1926)
return commandArray
If you want the numbers from a specific country, you can do vor example:
https://coronavirus-19-api.herokuapp.co ... etherlands
I run this scheduled on a windows machine and output it to a .txt file in the domoticz folder.
-
- Posts: 17
- Joined: Monday 25 April 2016 10:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Graph question
Thanks!
- laco
- Posts: 86
- Joined: Tuesday 30 October 2018 12:57
- Target OS: NAS (Synology & others)
- Domoticz version: 2021.1
- Location: Slovensko
- Contact:
Re: Graph question
I have domoticz running on synology nas server.
How do I set up reading in the LUA script https://coronavirus-19-api.herokuapp.co ... s/Slovakia
How do I set up reading in the LUA script https://coronavirus-19-api.herokuapp.co ... s/Slovakia
-
- Posts: 153
- Joined: Tuesday 28 June 2016 16:38
- Target OS: Windows
- Domoticz version: Beta
- Location: Amersfoort NL
- Contact:
Re: Graph question
No idea, i'm running on windows.
-
- Posts: 21
- Joined: Thursday 22 October 2015 19:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: bèta
- Location: Netherlands
- Contact:
Re: Graph question
I made a bash script for world wide statistics.
With a litte editing you can use it for your own country.
I saved the file into /home/pi/domoticz/scripts/sh/corona_stats.sh
With a litte editing you can use it for your own country.
I saved the file into /home/pi/domoticz/scripts/sh/corona_stats.sh
Code: Select all
#!/bin/bash
# /home/pi/domoticz/scripts/sh/corona_stats.sh
# Make 3 virtual sensors in Domoticz and name them WW_Cases, WW_Deaths and WW_Recovered
# Note the three IDX numbers of the counters and fill them into CASES_IDX, DEATHS_IDX, RECOVERED_IDX
# Make a SSH connection with your domoticz device and start crontab -e
# Put the rule below into crontab and save it
# * * * * * /home/pi/domoticz/scripts/sh/corona_stats.sh
# Now every minute there will be an update of the stats.
# Settings
CORONA_STATS_WEBSITE="https://coronavirus-19-api.herokuapp.com/all" # Corona stats website
DOMO_IP="192.168.1.100" # Domoticz IP (e.g. 192.168.1.100)
DOMO_PORT="8080" # Domoticz port (e.g. 8080)
CASES_IDX='855' # Domoticz IDX number of cases
DEATHS_IDX='856' # Domoticz IDX number of deaths
RECOVERED_IDX='857' # Domoticz IDX number of recovered
# Get data from Corona website
INPUT=$(curl "$CORONA_STATS_WEBSITE")
CASES=$(echo "$INPUT" | awk -v FS="(:|,)" '{print $2//['}']/}')
DEATHS=$(echo "$INPUT" | awk -v FS="(:|,)" '{print $4//['}']/}')
RECOVERED=$(echo "$INPUT" | awk -v FS="(:|,)" '{print $6//['}']/}')
echo
echo Number of infections.: $CASES
echo Number of deaths.....: $DEATHS
echo Number of recovered..: $RECOVERED
# Load data in domoticz
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$CASES_IDX&nvalue=0&svalue=$CASES"
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$DEATHS_IDX&nvalue=0&svalue=$DEATHS"
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command¶m=udevice&idx=$RECOVERED_IDX&nvalue=0&svalue=$RECOVERED"
-
- Posts: 17
- Joined: Monday 25 April 2016 10:27
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Graph question
I use a DzVent script. It's simpler and more or less standalone (apart from the custom sensor).
- Spoiler: show
-
- Posts: 153
- Joined: Tuesday 28 June 2016 16:38
- Target OS: Windows
- Domoticz version: Beta
- Location: Amersfoort NL
- Contact:
Re: Graph question
Nice, now let's hope the "cases" and "deaths" counters stop counting real soon....
Who is online
Users browsing this forum: No registered users and 1 guest