how to read value from web page

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
ladekribs
Posts: 7
Joined: Wednesday 18 May 2016 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

how to read value from web page

Post by ladekribs »

Hello all,

Maybe this question has been asked before, but I cannot find any answer.

I have a web switch that puts out One-Wire reading as a number value only, the same are also available from webpages.

So How can I read that value into Domoticz as a temperature sensor?

Best regards Stefan
georgesattali
Posts: 84
Joined: Saturday 05 March 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: how to read value from web page

Post by georgesattali »

Hello,
what http adresse do you use and what does it print ?

could you connect to your rapsberry and type the following command :

curl -s 'http://xxxxxxx'

with xxxxxx the web adress you would type from Firefox ?

what do you get ?
ladekribs
Posts: 7
Joined: Wednesday 18 May 2016 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: how to read value from web page

Post by ladekribs »

Thank You georgesattali,

if I connect to web switch with
http://x.x.x.x/temperature/get/1 where 1 is first temp sensor I get the response:
|000|OK|37.06|
the format is ”|000|OK|[status/value]”
I get the same with curl

and even better from a external webpage where I get only the temp number as: 34.8

but how do I import it to Domoticz?

BR Stefan
georgesattali
Posts: 84
Joined: Saturday 05 March 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: how to read value from web page

Post by georgesattali »

Hello ladekribe,

I propose you this solution, I think there is another solution with lua_parsers, but I know this one better.

First, check that you already have a "Dummy" hardware (Setup/Hardware), if you don't have it, you have to create it : choose Type = Dummy, name it (usually "Virtual") and click Add.

Second, you have to create a virtual sensor (Create virtual sensor). In this case, "Sensor Type:" must be "Temperature". Name it as you like.

Third, create an lua script, either by Linux if you are familiar with or with the menu "Setup/Event", select Lua instead of Blockly. click All and choose Time. (this is a "time" script, executed every minutes)

Fourth, copy and paste the following code in the lua editor. You have of course to change the x.x.x.x and IDX to the idx of your virtual device (a number, for ex 92 or 146 - you can see it in Setup/Devices).

Code: Select all

commandArray = {}
now=os.date("*t")

-- NB : every 5 minutes only, if u prefer every 2 min or even every 1 min
--      change the 5 below
if now.min % 5 == 0 then
   local f = assert(io.popen("curl -s http://x.x.x.x/temperature/get/1" , 'r'))
   local s = assert(f:read('*a'))
   local threeZero, status, temp = s:match("|([^|]*)|([^|]*)|([^|]*)|")
   if status == "OK" then
      -- you can see prints in Setup/Log
      print("One-Wire : read and update 1 : "..s.."=>"..temp)
      commandArray["UpdateDevice"] = IDX.."|0|"..temp
   else
      print("One-Wire : bad status : "..s)
   end
end
return commandArray
Should work - but you'll tell,
See you, GD
ladekribs
Posts: 7
Joined: Wednesday 18 May 2016 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: how to read value from web page

Post by ladekribs »

Thank You georgesattali,

sorry for late answer, I had to reinstall domoticz

I now get in the log:
2016-06-05 07:48:00.393 LUA: One-Wire : read and update 1 : |000|OK|37.43|=>37.43
so that looks good, but i have no clue in how the IDX should be entered

if I write
commandArray["UpdateDevice"] = '4|0|..temp'
I get
2016-06-05 07:50:05.862 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_time_tempWSread.lua
but the dummy sensor(idx=4) stays at 0 degrees

BR Stefan
georgesattali
Posts: 84
Joined: Saturday 05 March 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: how to read value from web page

Post by georgesattali »

hello Stefan,
maybe the quote is misplaced in the instruction below :
commandArray["UpdateDevice"] = '4|0|..temp'

should be :
commandArray["UpdateDevice"] = '4|0|'..temp

Bye,
GD
ladekribs
Posts: 7
Joined: Wednesday 18 May 2016 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: how to read value from web page

Post by ladekribs »

yes! now it works, super!

this opens many possibillities

Thank You Georgesattali
arisg
Posts: 1
Joined: Wednesday 17 May 2017 0:57
Target OS: Windows
Domoticz version:
Contact:

Re: how to read value from web page

Post by arisg »

I am straggling for 2 days 24/day to make lua script like yours but i can do it.
i need to read an sensors and put it in my Domoticz from my Arduino
the path is http://192.168.0.197/arduino/digital/2 and the replay is:
Pin D2 set to 0
the other sensors are in
http://192.168.0.197/arduino/analog/2 the replay is:
Pin A2 reads analog 521
I want to delete x characters in front and i just cant make it heppen
can someone help me pls ?
Best Regard
Aris
ladekribs
Posts: 7
Joined: Wednesday 18 May 2016 17:01
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: how to read value from web page

Post by ladekribs »

Hello Aris,

I know nothing of Lua, but to me it looks like you need to do some truncation.

have a look at http://lua-users.org/wiki/StringRecipes and see if that would help you?

regards Stefan
RayAmsterdam
Posts: 115
Joined: Sunday 11 January 2015 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: how to read value from web page

Post by RayAmsterdam »

I am trying to use this script to scrape the following url: https://rvormer.herokuapp.com/api/v1/en ... rrent/json.
I want to scrape the sgv value and later on maybe also the direction value.
I'm new to Lua and don't know what to replace in the match command. Can somebody help me?
jackrobijn
Posts: 18
Joined: Thursday 10 May 2018 10:14
Target OS: Raspberry Pi / ODroid
Domoticz version: V8.153
Location: Oss The Netherlands
Contact:

Re: how to read value from web page

Post by jackrobijn »

georgesattali wrote: Tuesday 31 May 2016 22:27 Hello ladekribe,

I propose you this solution, I think there is another solution with lua_parsers, but I know this one better.

First, check that you already have a "Dummy" hardware (Setup/Hardware), if you don't have it, you have to create it : choose Type = Dummy, name it (usually "Virtual") and click Add.

Second, you have to create a virtual sensor (Create virtual sensor). In this case, "Sensor Type:" must be "Temperature". Name it as you like.

Third, create an lua script, either by Linux if you are familiar with or with the menu "Setup/Event", select Lua instead of Blockly. click All and choose Time. (this is a "time" script, executed every minutes)

Fourth, copy and paste the following code in the lua editor. You have of course to change the x.x.x.x and IDX to the idx of your virtual device (a number, for ex 92 or 146 - you can see it in Setup/Devices).

Code: Select all

commandArray = {}
now=os.date("*t")

-- NB : every 5 minutes only, if u prefer every 2 min or even every 1 min
--      change the 5 below
if now.min % 5 == 0 then
   local f = assert(io.popen("curl -s http://x.x.x.x/temperature/get/1" , 'r'))
   local s = assert(f:read('*a'))
   local threeZero, status, temp = s:match("|([^|]*)|([^|]*)|([^|]*)|")
   if status == "OK" then
      -- you can see prints in Setup/Log
      print("One-Wire : read and update 1 : "..s.."=>"..temp)
      commandArray["UpdateDevice"] = IDX.."|0|"..temp
   else
      print("One-Wire : bad status : "..s)
   end
end
return commandArray
Should work - but you'll tell,
See you, GD
Dear George

Found your reply, but strugling to get it working

Would you please also help me with this

I am trying the same as ladekribe
Reading several Onewire sensors from a WebCai board with http://X.X.X.X/gett2.cgi where t2 is sensor 2
HTTP reading works fine, and getting | 25,6 C| as return
I do not get the 000|status|Status/Value as ladekribe mentioned

How to rewrite your script so that the import is correctly.

So importing the value 25,6 (not the C)

If I used your code, then the log shows
2018-05-10 11:37:57.485 Error: EventSystem: in IDX49: [string "commandArray = {} ..."]:13: unexpected symbol near '"|0|"'

MAny thanks in advance

Jack
5 x raspberry with Domoticz, open hab, Home assitant, OpenElec Kodi.
Interests Home automation
jackrobijn
Posts: 18
Joined: Thursday 10 May 2018 10:14
Target OS: Raspberry Pi / ODroid
Domoticz version: V8.153
Location: Oss The Netherlands
Contact:

Re: how to read value from web page

Post by jackrobijn »

Goodmorning George.

I had already send you a PM but stays in my outbox for some reason?
So I try it once more through this channel

I have read your conversation and help with ladkrive on june206 with great interest.
I have a simular problem and cannot get your lua script to ladekribe to work. :oops:
I am reading 8 x 1 wire sensors connected to WEBCAi board
In a webpage i get result by using http://192.168.3.185/gett1.cgi to read the value for T1
outcome is then |25.7 C|. (without the brackets so 25.7 C)
I am strugling to get your lua script working, probable because the match string is incorrect, but after days of searching stil cannot find the correct answer, so hopefully you are willing to help me.

Would aslo be possible to use 1 lua script to read all 8 sensors from the board T1-T8 and sent these valuas to virtual sensors IDX200-207 are easier to use seperate lua scripts.
This is for a hobby project at home to read and measure my CV heating water temp in-out and 5 floorheating groups.
Later stage of the project is to write all the sensor values in to a db server together with gas usage etc.

Would be much appriciated if you wiling to help me with the correct lua script
5 x raspberry with Domoticz, open hab, Home assitant, OpenElec Kodi.
Interests Home automation
User avatar
luberth
Posts: 34
Joined: Friday 27 April 2018 7:56
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: Bangert 30 Andijk Nederland
Contact:

Re: how to read value from web page

Post by luberth »

Domoticz temperature from another raspberri pi sensor

i do not know what i am doing wrong
but i do get only bad status
it is working
when i put
commandArray['UpdateDevice']='13|0|'..s
after the else on the bad side

i have domoticz on smartgridmeter raspberry pi 3b
i have temperature sensor on my desktop raspberry pi 3b+ running php webserver
lua script entered in domoticz editor called the script temp (temp lua time event active)
hardware idx7 dummy
devices type temp idx = 13

Code: Select all

commandArray = {}
now=os.date("*t")

-- NB : every 5 minutes only, if u prefer every 2 min or even every 1 min
--      change the 5 below
if now.min % 1 == 0 then
   local f = assert(io.popen("curl -s http://84.106.2.21:8888/temperaturedom.php" , 'r'))
   local s = assert(f:read('*a'))
   local threeZero, status, temp = s:match("|([^|]*)|([^|]*)|([^|]*)|")
   if status == "OK" then
      -- you can see prints in Setup/Log
      print("One-Wire : read and update 13 : "..s.."=>"..temp)
      commandArray['UpdateDevice']='13|0|'..temp 
   else
      print("One-Wire : bad status : "..s)
      -- whe are on the bad status side of else but this way its working for me next line should not be here
      commandArray['UpdateDevice']='13|0|'..s 
   end
end


return commandArray

2018-10-23 16:06:01.706 (Slimme Meter Kabel) P1 Smart Meter (Power 12-4-2018)
2018-10-23 16:06:01.707 (Slimme Meter Kabel) General/Voltage (Voltage L1)
2018-10-23 16:06:01.354 Status: LUA: One-Wire : bad status :
2018-10-23 16:06:01.354
2018-10-23 16:06:01.354 22.50
2018-10-23 16:06:01.355 Status: EventSystem: Script event triggered: temp
2018-10-23 16:06:02.711 (Slimme Meter Kabel) P1 Smart Meter (Power 12-4-2018)
2018-10-23 16:06:02.713 (Slimme Meter Kabel) General/Voltage (Voltage L1)


2018-10-23 23:27:01.408 (Slimme Meter Kabel) General/Voltage (Voltage L1)
2018-10-23 23:27:01.461 Status: LUA: One-Wire : bad status : 23.50
2018-10-23 23:27:01.463 Status: EventSystem: Script event triggered: temp


the errors i get with the example on this page
2018-10-23 14:23:00.308 Error: EventSystem: in temperature: [string "commandArray = {}..."]:15: attempt to concatenate local 'temp' (a nil value)
2018-10-23 14:36:00.439 Error: EventSystem: in temperature: [string "commandArray = {}..."]:15: attempt to concatenate global 'tempy' (a nil valu
2018-10-23 15:01:00.213 Error: EventSystem: in temperature: [string "commandArray = {}..."]:18: attempt to concatenate global 's' (a nil value)
2018-10-23 15:26:01.438 Error: EventSystem: in temperature: [string "commandArray = {}..."]:19: attempt to concatenate global 's' (a nil value)
2018-10-23 15:40:01.117 Error: EventSystem: in temp: [string "commandArray = {}..."]:17: attempt to concatenate local 'temp' (a nil value)

code i use for writing sensor data to php webpage (not the domoticz raspberrypi, another one wich i use as desktop computer)
http://84.106.2.21:8888/temperaturedom.php

Code: Select all

<?php
$file = '/sys/devices/w1_bus_master1/28-00000a2a21f8/w1_slave';
$lines = file($file);
$temp = explode('=', $lines[1]);
$temp = number_format($temp[1] / 1000, 2, '.', '');
echo $temp;
?>



http://test:[email protected]:8080/#/Dashboard
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest