CORONAVIRUS

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.

Moderators: leecollings, remb0

Post Reply
User avatar
laco
Posts: 86
Joined: Tuesday 30 October 2018 12:57
Target OS: NAS (Synology & others)
Domoticz version: 2021.1
Location: Slovensko
Contact:

CORONAVIRUS

Post 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
User avatar
felix63
Posts: 244
Joined: Monday 07 December 2015 9:30
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Gouda
Contact:

Re: CORONAVIRUS

Post 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
}
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: CORONAVIRUS

Post 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
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: CORONAVIRUS

Post by laco »

I've already found it

Code: Select all

timer = { 'every 10 minutes'}
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: CORONAVIRUS

Post by laco »

Can you create a script for the world?

https://coronavirus-19-api.herokuapp.com/all

Thank you!
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: CORONAVIRUS

Post by elmortero »

laco wrote: Sunday 22 March 2020 17:58 Can you create a script for the world?

https://coronavirus-19-api.herokuapp.com/all

Thank you!
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
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: CORONAVIRUS

Post 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
}
Image
Joost996me
Posts: 18
Joined: Sunday 12 February 2017 15:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: CORONAVIRUS

Post by Joost996me »

Works great, thx. Now let's all hope this counters will stop counting.
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: CORONAVIRUS

Post 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
kniazio
Posts: 198
Joined: Thursday 06 October 2016 8:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.7243
Contact:

Re: CORONAVIRUS

Post 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)
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: CORONAVIRUS

Post by laco »

elmortero wrote: Sunday 22 March 2020 21:55 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
How do I change the counter icon?
I don't see an option.
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: CORONAVIRUS

Post 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
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: CORONAVIRUS

Post 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.
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: CORONAVIRUS

Post 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
}
User avatar
gielie
Posts: 290
Joined: Tuesday 12 January 2016 11:40
Target OS: Raspberry Pi / ODroid
Domoticz version: latest β
Location: The Netherlands (Alkmaar)
Contact:

Re: CORONAVIRUS

Post 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
- Aeon Labs USB Stick met Z-wave plus
- Aeotec MultiSensor 6
- FIBARO FGS223
- FIBARO FGWPE Wall Plug
- Neo CoolCam Power plug
- Popp Smoke Detector
- Toon
- Kodi Media Server
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: CORONAVIRUS

Post by elmortero »

My mistake guys.
Counter icons cannot be changed.
I used custom sensor and not a counter in my setup
kniazio
Posts: 198
Joined: Thursday 06 October 2016 8:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.7243
Contact:

Re: CORONAVIRUS

Post 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?
Attachments
telegram.jpg
telegram.jpg (77.23 KiB) Viewed 1706 times
User avatar
gielie
Posts: 290
Joined: Tuesday 12 January 2016 11:40
Target OS: Raspberry Pi / ODroid
Domoticz version: latest β
Location: The Netherlands (Alkmaar)
Contact:

Re: CORONAVIRUS

Post 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?
- Aeon Labs USB Stick met Z-wave plus
- Aeotec MultiSensor 6
- FIBARO FGS223
- FIBARO FGWPE Wall Plug
- Neo CoolCam Power plug
- Popp Smoke Detector
- Toon
- Kodi Media Server
alanlsmith
Posts: 132
Joined: Monday 07 August 2017 17:17
Target OS: Linux
Domoticz version: Latest β
Location: Near London (Saaarf!)
Contact:

Re: CORONAVIRUS

Post 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.
Domoticz Latest β, RPi 4B with 110Gb SSD for Domoticz, RPi 4B with 110Gb SSD for Node-Red & a RPi 2B for logging / IP addressing. RFXCOM, PiZiGate, Z-Wave, Harmony, Hue lamps and a bit of Broadlink.
prychol
Posts: 3
Joined: Friday 24 April 2020 19:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Polska
Contact:

Re: CORONAVIRUS

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest