Graph question

Dashticz, alternative dashboard based on HTML, CSS, jQuery

Moderators: leecollings, htilburgs, robgeerts

Post Reply
JimmyH1969
Posts: 153
Joined: Tuesday 28 June 2016 16:38
Target OS: Windows
Domoticz version: Beta
Location: Amersfoort NL
Contact:

Graph question

Post by JimmyH1969 »

Hi,

I have a Custom Sensor in Domoticz that counts the infected corona people. In Domoticz this works fine.
Domoticz counter.jpg
Domoticz counter.jpg (19.37 KiB) Viewed 1160 times
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.
Dashticz counter.jpg
Dashticz counter.jpg (104.3 KiB) Viewed 1160 times
Any clue?
Janco
Posts: 17
Joined: Monday 25 April 2016 10:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Graph question

Post by Janco »

Can't answer your question, but how did you set up this sensor in Domoticz?
JimmyH1969
Posts: 153
Joined: Tuesday 28 June 2016 16:38
Target OS: Windows
Domoticz version: Beta
Location: Amersfoort NL
Contact:

Re: Graph question

Post by JimmyH1969 »

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:

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
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.
Janco
Posts: 17
Joined: Monday 25 April 2016 10:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Graph question

Post by Janco »

Thanks!
User avatar
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

Post by laco »

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
JimmyH1969
Posts: 153
Joined: Tuesday 28 June 2016 16:38
Target OS: Windows
Domoticz version: Beta
Location: Amersfoort NL
Contact:

Re: Graph question

Post by JimmyH1969 »

No idea, i'm running on windows.
Mike70
Posts: 21
Joined: Thursday 22 October 2015 19:46
Target OS: Raspberry Pi / ODroid
Domoticz version: bèta
Location: Netherlands
Contact:

Re: Graph question

Post by Mike70 »

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

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&param=udevice&idx=$CASES_IDX&nvalue=0&svalue=$CASES"
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DEATHS_IDX&nvalue=0&svalue=$DEATHS"
curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$RECOVERED_IDX&nvalue=0&svalue=$RECOVERED"
Janco
Posts: 17
Joined: Monday 25 April 2016 10:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Graph question

Post by Janco »

I use a DzVent script. It's simpler and more or less standalone (apart from the custom sensor).
Spoiler: show
return {
on = {
timer = { 'every hour' },
httpResponses = { 'coronaRetrieved' }
},
execute = function(domoticz, item)
if (item.isTimer) then
domoticz.openURL({
url = 'https://coronavirus-19-api.herokuapp.com/all',
method = 'GET',
callback = 'coronaRetrieved'
})
elseif (item.isHTTPResponse) then
if (item.ok) then -- statusCode == 2xx
local current = item.json.cases
domoticz.log(item.json.cases)
domoticz.devices('Corona Cases').updateCustomSensor(item.json.cases)
domoticz.log(item.json.deaths)
domoticz.devices('Corona Deaths').updateCustomSensor(item.json.deaths)
domoticz.log(item.json.recovered)
domoticz.devices('Corona Recovered').updateCustomSensor(item.json.recovered)
end
end
end
}
It retrieves the data for the whole word. It can be easily adapted for specific countries though.
JimmyH1969
Posts: 153
Joined: Tuesday 28 June 2016 16:38
Target OS: Windows
Domoticz version: Beta
Location: Amersfoort NL
Contact:

Re: Graph question

Post by JimmyH1969 »

Nice, now let's hope the "cases" and "deaths" counters stop counting real soon....
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest