Hi,
I have read some other discussions but I do not really have a clue how to create a working script to import data from a different automation system into domoticz.
The other system is working autonomous fine and has several sensors installed in my house already and I like to get this data in domoticz.
When I open the webpage the respond looks like in the attachment file.
I want to import the temperature value of 11,9403 degrees Celsius into domoticz every 5 minutes.
Really appreciate any help here, when I know how its working for 1 sensor I am sure I can adapt for the others.
Import data from website into domoticz sensor script
Moderators: leecollings, remb0
-
- Posts: 3
- Joined: Tuesday 19 July 2022 17:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Import data from website into domoticz sensor script
- Attachments
-
- webpoll.JPG (57.78 KiB) Viewed 454 times
-
- Posts: 642
- Joined: Saturday 21 September 2019 17:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.1
- Location: The Netherlands
- Contact:
Re: Import data from website into domoticz sensor script
Have a look at the documentation how to use dzVents to do asynchronous shell command execution.
Assuming you are on a Linux system, you could use "cat filename | grep href | awk -F">" '{print $3}' | awk -F"<" '{ print $1}' "
to get the value out of the example file above (replace filename by your filename of course)
1) grep selects the line with "href" in it from the file
2) the first awk selects the 3rd field of the that line, using field separator ">"
3) the second awk selects the 1st field of the result of step2, with field separator "<" which is the value you want
The value will be in item.data once the command has been executed. Might needed conversion to number. You can then assign that value to a device or do anything else with it that you want.
I don't want to spell it out for you .... much more rewarding to discover yourself how this works
Assuming you are on a Linux system, you could use "cat filename | grep href | awk -F">" '{print $3}' | awk -F"<" '{ print $1}' "
to get the value out of the example file above (replace filename by your filename of course)
1) grep selects the line with "href" in it from the file
2) the first awk selects the 3rd field of the that line, using field separator ">"
3) the second awk selects the 1st field of the result of step2, with field separator "<" which is the value you want
The value will be in item.data once the command has been executed. Might needed conversion to number. You can then assign that value to a device or do anything else with it that you want.
I don't want to spell it out for you .... much more rewarding to discover yourself how this works

-
- Posts: 3
- Joined: Tuesday 19 July 2022 17:11
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Import data from website into domoticz sensor script
Hi, sorry about missing out the main info:
I am running domoticz on a raspberry pi3B
Thanks for your idea with the linux script.
Can you imagine to work with a script instead (lua/dzvents)?
It will be easier to maintain within the domoticz scripts backup etc.
I am running domoticz on a raspberry pi3B
Thanks for your idea with the linux script.
Can you imagine to work with a script instead (lua/dzvents)?
It will be easier to maintain within the domoticz scripts backup etc.
- Attachments
-
- domoticz version.JPG (31.86 KiB) Viewed 425 times
- waltervl
- Posts: 5843
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Import data from website into domoticz sensor script
Here is a DzVents example to scrape an html page: https://domoticz.com/forum/viewtopic.ph ... 54#p223354
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
-
- Posts: 642
- Joined: Saturday 21 September 2019 17:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.1
- Location: The Netherlands
- Contact:
Re: Import data from website into domoticz sensor script
Actually, the example I gave is a unix shell command, but what I suggested was to launch this shell command from within a Dzvents script as a asynchronous command. So you develop a dzVents script to get the value and then do whatever you want with that value, such as store it in a device, perform checks on it, make decision based on it, etc etc. This script is fully stored within the domoticz dbase and also included in the backup. The only unix shell part of the script is the single line of my example which is within the dzVents script as a asynchronous command.TomDoRpi wrote: ↑Monday 02 January 2023 13:03 Hi, sorry about missing out the main info:
I am running domoticz on a raspberry pi3B
Thanks for your idea with the linux script.
Can you imagine to work with a script instead (lua/dzvents)?
It will be easier to maintain within the domoticz scripts backup etc.
Here is a small example based on the same principle. It is a dzvent script that launches a shell script command to check disk usage and then reports it back in the domoticz log.
Code: Select all
local diskused='diskused'
return {
on = {
timer = {
'every hour'
},
shellCommandResponses =
{
diskused,
},
},
logging = {
level = domoticz.LOG_INFO,
marker = 'template',
},
execute = function(domoticz, item)
if item.isTimer then
domoticz.executeShellCommand({
command = 'df -h /media/usbdisk | grep media | awk \'{print $5}\' | awk -F% \'{print $1}\'',
callback = diskused,
timeout = 5,
})
else
domoticz.log('Disk used % ' .. tonumber(item.data), domoticz.LOG_INFO)
if tonumber(item.data)<50 then
domoticz.log('Enough space left. Disk used ' .. item.data, domoticz.LOG_INFO)
else
domoticz.log('Watch your disk space. Disk used ' .. item.data, domoticz.LOG_INFO)
end
end
end
}
Who is online
Users browsing this forum: No registered users and 1 guest