Page 1 of 1
CORONAVIRUS
Posted: Sunday 22 March 2020 15:00
by laco
Can anyone create a dzvents script from coronavirus data into virtual scanners?
API:
World:
https://coronavirus-19-api.herokuapp.com/all
Slovakia:
https://coronavirus-19-api.herokuapp.co ... s/Slovakia
well thank you
Re: CORONAVIRUS
Posted: Sunday 22 March 2020 15:39
by felix63
Create two (or more) virtual counters and edit the type of the counter to 'Counter'. I use
'Corona deaths total'
'Corona deaths today'
In the script change the local variable to reflect the country you want to collect the data from. Typically the data gets updated just once per day so there is no need to run it more often.
The script:
Code: Select all
return {
-- Function:
--
-- This script retrieves static data from RPI-monitor instances.
-- The script uses the RPI-monitor API to retrieve static data once a month or at restart. The data is stored in
-- custom variables.
--
on = {
timer = {
'every day at 15:45' -- just an example to trigger the request
},
system = {
'start',
},
httpResponses = {
'Status_Corona', -- must match with the callback passed to the openURL command
},
},
execute = function(domoticz, item)
local country = 'Netherlands'
if (item.isTimer or item.isDevice or item.isService) then
domoticz.openURL({
url = 'https://coronavirus-19-api.herokuapp.com/countries/' .. country,
method = 'GET',
callback = 'Status_Corona', -- see httpResponses above.
})
end
if (item.isHTTPResponse) then
if (item.statusCode == 200) then
if (item.isJSON) then
if (item.callback == 'Status_Corona') then
domoticz.devices('Corona deaths today').updateCounter(item.json.todayDeaths)
domoticz.devices('Corona deaths total').updateCounter(item.json.deaths)
end
end
else
domoticz.log('There was a problem handling the request ' .. item.callback, domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end
end
end
}
Re: CORONAVIRUS
Posted: Sunday 22 March 2020 16:25
by laco
Thank you, it works great.
World data is updated on an ongoing basis.
How do I make them update every 10 minutes, for example?
https://coronavirus-19-api.herokuapp.com/all
Re: CORONAVIRUS
Posted: Sunday 22 March 2020 16:31
by laco
Re: CORONAVIRUS
Posted: Sunday 22 March 2020 17:58
by laco
Can you create a script for the world?
https://coronavirus-19-api.herokuapp.com/all
Thank you!
Re: CORONAVIRUS
Posted: Sunday 22 March 2020 18:14
by elmortero
You can do that yourself easily Laco.
1. Create a new sensor for total deaths worldwide (the api does not output numbers of deaths per day)
2. Change the callback on line 17 and 28 --> they have to be equal and not be the same as the one from another script
3. Change the url on line 26 to
https://coronavirus-19-api.herokuapp.com/all --> make sure to remove the part .. country
4. Put the name of that sensor on line 37 instead of ('Corona deaths total')
5. Remove line 36
Re: CORONAVIRUS
Posted: Sunday 22 March 2020 18:55
by laco
Well thank you.
I enclose a finished dzvents script if someone needed Slovakia and the world
SK:
Code: Select all
return {
-- Function:
--
-- This script retrieves static data from RPI-monitor instances.
-- The script uses the RPI-monitor API to retrieve static data once a month or at restart. The data is stored in
-- custom variables.
--
on = {
timer = { 'every 30 minutes'},
system = {
'start',
},
httpResponses = {
'Status_Corona', -- must match with the callback passed to the openURL command
},
},
execute = function(domoticz, item)
local country = 'Slovakia'
if (item.isTimer or item.isDevice or item.isService) then
domoticz.openURL({
url = 'https://coronavirus-19-api.herokuapp.com/countries/' .. country,
method = 'GET',
callback = 'Status_Corona', -- see httpResponses above.
})
end
if (item.isHTTPResponse) then
if (item.statusCode == 200) then
if (item.isJSON) then
if (item.callback == 'Status_Corona') then
domoticz.devices('Corona nakazení Slovensko').updateCounter(item.json.cases)
domoticz.devices('Corona zomreli dnes').updateCounter(item.json.todayDeaths)
domoticz.devices('Corona zomreli celkovo').updateCounter(item.json.deaths)
end
end
else
domoticz.log('There was a problem handling the request ' .. item.callback, domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end
end
end
}
World:
Code: Select all
return {
-- Function:
--
-- This script retrieves static data from RPI-monitor instances.
-- The script uses the RPI-monitor API to retrieve static data once a month or at restart. The data is stored in
-- custom variables.
--
on = {
timer = { 'every 10 minutes'},
system = {
'start',
},
httpResponses = {
'Status_Corona_all', -- must match with the callback passed to the openURL command
},
},
execute = function(domoticz, item)
local country = 'all'
if (item.isTimer or item.isDevice or item.isService) then
domoticz.openURL({
url = 'https://coronavirus-19-api.herokuapp.com/' .. country,
method = 'GET',
callback = 'Status_Corona_all', -- see httpResponses above.
})
end
if (item.isHTTPResponse) then
if (item.statusCode == 200) then
if (item.isJSON) then
if (item.callback == 'Status_Corona_all') then
domoticz.devices('Corona nakazení vo svete').updateCounter(item.json.cases)
domoticz.devices('Corona zomreli vo svete').updateCounter(item.json.deaths)
domoticz.devices('Corona uzdravení vo svete').updateCounter(item.json.recovered)
end
end
else
domoticz.log('There was a problem handling the request ' .. item.callback, domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end
end
end
}

Re: CORONAVIRUS
Posted: Sunday 22 March 2020 19:30
by Joost996me
Works great, thx. Now let's all hope this counters will stop counting.
Re: CORONAVIRUS
Posted: Sunday 22 March 2020 21:55
by elmortero
HI.
I made 2 custom icons for the counters.
One represents the corona virus, the other one is for the number of deaths counter
https://www.domoticz.com/forum/viewtopi ... 33#p240233
Re: CORONAVIRUS
Posted: Sunday 22 March 2020 22:00
by kniazio
I'm trying to add a script and I can't do anything about it.
Errors only in logs.
What script is this supposed to be? lua, python, dzVents?
Is the script to be added in Events?
Which sensor should I choose exactly?
Counter / Counter?
Do I need to add anything to the sensor settings?
P.S.
Everything is working now
Tell me how to set a notification to Telegram
If the number of infected increases by at least 1 then send a message
I have set:
Last update
Greater
Value (I don't know what to insert here)
Re: CORONAVIRUS
Posted: Monday 23 March 2020 15:20
by laco
How do I change the counter icon?
I don't see an option.
Re: CORONAVIRUS
Posted: Monday 23 March 2020 15:29
by elmortero
First go to Setup--Custom Icon -menu to upload the zip files with the icons
Then click on the Edit button of your counter in order to select a sensor icon
Re: CORONAVIRUS
Posted: Monday 23 March 2020 15:55
by laco
elmortero wrote: ↑Monday 23 March 2020 15:29
First go to Setup--Custom Icon -menu to upload the zip files with the icons
Then click on the Edit button of your counter in order to select a sensor icon
I click edit counters, but I can't change the icon there.
Re: CORONAVIRUS
Posted: Wednesday 25 March 2020 13:49
by elmortero
kniazio wrote: ↑Sunday 22 March 2020 22:00
Tell me how to set a notification to Telegram
If the number of infected increases by at least 1 then send a message
I have set: Last update Greater Value (I don't know what to insert here)
try this one (adapt your settings to your needs)
Code: Select all
return {
-- Function:
--
-- This script retrieves static data from RPI-monitor instances.
-- The script uses the RPI-monitor API to retrieve static data once a month or at restart. The data is stored in
-- custom variables.
--
on = {
timer = { 'every 30 minutes'},
system = {
'start',
},
httpResponses = {
'Status_Corona', -- must match with the callback passed to the openURL command
},
},
execute = function(domoticz, item)
local country = 'Slovakia'
if (item.isTimer or item.isDevice or item.isService) then
domoticz.openURL({
url = 'https://coronavirus-19-api.herokuapp.com/countries/' .. country,
method = 'GET',
callback = 'Status_Corona', -- see httpResponses above.
})
end
if (item.isHTTPResponse) then
if (item.statusCode == 200) then
if (item.isJSON) then
if (item.callback == 'Status_Corona') then
local prevcountC = domoticz.devices('Corona nakazení Slovensko').counter --get the value of the counter for cases
local prevcountT = domoticz.devices('Corona zomreli dnes').counter --get the value of the counter for todayDeaths
local prevcountD = domoticz.devices('Corona zomreli celkovo').counter --get the value of the counter for (total)deaths
domoticz.devices('Corona nakazení Slovensko').updateCounter(item.json.cases)
domoticz.devices('Corona zomreli dnes').updateCounter(item.json.todayDeaths)
domoticz.devices('Corona zomreli celkovo').updateCounter(item.json.deaths)
if item.json.cases > prevcountC then -- change cases to todayDeaths or deaths according to what you want to
-- compare and change prevcountC also accordingly
--your actions/notifications here
end
end
end
else
domoticz.log('There was a problem handling the request ' .. item.callback, domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end
end
end
}
Re: CORONAVIRUS
Posted: Wednesday 25 March 2020 15:27
by gielie
laco wrote: ↑Monday 23 March 2020 15:55
elmortero wrote: ↑Monday 23 March 2020 15:29
First go to Setup--Custom Icon -menu to upload the zip files with the icons
Then click on the Edit button of your counter in order to select a sensor icon
I click edit counters, but I can't change the icon there.
I have the same problem, to my knowledge you can not change a counter icon, so im very curious how ts did this.
If I create a custom sensor it won't get updated, if I create a counter it does work but without changing the icon
Re: CORONAVIRUS
Posted: Wednesday 25 March 2020 16:22
by elmortero
My mistake guys.
Counter icons cannot be changed.
I used custom sensor and not a counter in my setup
Re: CORONAVIRUS
Posted: Thursday 26 March 2020 6:36
by kniazio
elmortero wrote: ↑Wednesday 25 March 2020 13:49
kniazio wrote: ↑Sunday 22 March 2020 22:00
Tell me how to set a notification to Telegram
If the number of infected increases by at least 1 then send a message
I have set: Last update Greater Value (I don't know what to insert here)
try this one (adapt your settings to your needs)
Code: Select all
return {
-- Function:
--
-- This script retrieves static data from RPI-monitor instances.
-- The script uses the RPI-monitor API to retrieve static data once a month or at restart. The data is stored in
-- custom variables.
--
on = {
timer = { 'every 30 minutes'},
system = {
'start',
},
httpResponses = {
'Status_Corona', -- must match with the callback passed to the openURL command
},
},
execute = function(domoticz, item)
local country = 'Slovakia'
if (item.isTimer or item.isDevice or item.isService) then
domoticz.openURL({
url = 'https://coronavirus-19-api.herokuapp.com/countries/' .. country,
method = 'GET',
callback = 'Status_Corona', -- see httpResponses above.
})
end
if (item.isHTTPResponse) then
if (item.statusCode == 200) then
if (item.isJSON) then
if (item.callback == 'Status_Corona') then
local prevcountC = domoticz.devices('Corona nakazení Slovensko').counter --get the value of the counter for cases
local prevcountT = domoticz.devices('Corona zomreli dnes').counter --get the value of the counter for todayDeaths
local prevcountD = domoticz.devices('Corona zomreli celkovo').counter --get the value of the counter for (total)deaths
domoticz.devices('Corona nakazení Slovensko').updateCounter(item.json.cases)
domoticz.devices('Corona zomreli dnes').updateCounter(item.json.todayDeaths)
domoticz.devices('Corona zomreli celkovo').updateCounter(item.json.deaths)
if item.json.cases > prevcountC then -- change cases to todayDeaths or deaths according to what you want to
-- compare and change prevcountC also accordingly
--your actions/notifications here
end
end
end
else
domoticz.log('There was a problem handling the request ' .. item.callback, domoticz.LOG_ERROR)
domoticz.log(item, domoticz.LOG_ERROR)
end
end
end
}
What should I enter in the Value field?
Re: CORONAVIRUS
Posted: Thursday 26 March 2020 14:18
by gielie
elmortero wrote: ↑Wednesday 25 March 2020 16:22
My mistake guys.
Counter icons cannot be changed.
I used custom sensor and not a counter in my setup
I think you made a mistake with this one too because a custom sensor cannot be updated with the info form your script resulting in the following error.
Code: Select all
Error (2.4.19): Method updateCounter is not available for device "Corona Sick" (deviceType=General, deviceSubType=Custom Sensor). If you believe this is not correct, please report.
Can you explain step by step what you did exactly?
Re: CORONAVIRUS
Posted: Thursday 26 March 2020 14:30
by alanlsmith
gielie wrote: ↑Thursday 26 March 2020 14:18
elmortero wrote: ↑Wednesday 25 March 2020 16:22
My mistake guys.
Counter icons cannot be changed.
I used custom sensor and not a counter in my setup
I think you made a mistake with this one too because a custom sensor cannot be updated with the info form your script resulting in the following error.
Code: Select all
Error (2.4.19): Method updateCounter is not available for device "Corona Sick" (deviceType=General, deviceSubType=Custom Sensor). If you believe this is not correct, please report.
Can you explain step by step what you did exactly?
You just need to change ".updateCounter" to ".updateCustomSensor" to the appropriate lines in your script.
Re: CORONAVIRUS
Posted: Friday 24 April 2020 19:51
by prychol
Hello
At the beginning I would like to apologize for my English, but I use Google's translator
I wanted to add to my Domoticz (Version: 2020.1) the above counters. I did everything as described, i.e. I added counter devices, the same names as in the scripts, but unfortunately the counters do not count anything. There are no errors in the logs. How can you check why scripts don't work?
EDIT:
It is working now:)
dzVents was disabled in: Configuration, Settings, Other
... and may the meter stop as soon as possible
EDIT2:
Please, give me a hint how to modify the code to download data about infected in specific regions or cities available on this page:
https://apify.com/vaclavrut/covid-pl
https://api.apify.com/v2/key-value-stor ... irect=true - region
https://api.apify.com/v2/datasets/L3VCm ... on&clean=1 - city