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.
Post Reply
ladekribs
Posts: 7
Joined: Wednesday 18 May 2016 17:01
Target OS: Raspberry Pi
Domoticz version:
Contact:

how to read value from web page

Post by ladekribs » Wednesday 25 May 2016 10:50

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: 103
Joined: Saturday 05 March 2016 17:40
Target OS: Raspberry Pi
Domoticz version:
Location: France
Contact:

Re: how to read value from web page

Post by georgesattali » Monday 30 May 2016 21:36

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
Domoticz version:
Contact:

Re: how to read value from web page

Post by ladekribs » Tuesday 31 May 2016 16:45

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: 103
Joined: Saturday 05 March 2016 17:40
Target OS: Raspberry Pi
Domoticz version:
Location: France
Contact:

Re: how to read value from web page

Post by georgesattali » 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

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

Re: how to read value from web page

Post by ladekribs » Sunday 05 June 2016 7:52

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: 103
Joined: Saturday 05 March 2016 17:40
Target OS: Raspberry Pi
Domoticz version:
Location: France
Contact:

Re: how to read value from web page

Post by georgesattali » Sunday 05 June 2016 21:02

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
Domoticz version:
Contact:

Re: how to read value from web page

Post by ladekribs » Monday 06 June 2016 6:48

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 » Wednesday 17 May 2017 1:04

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
Domoticz version:
Contact:

Re: how to read value from web page

Post by ladekribs » Thursday 18 May 2017 9:50

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: 190
Joined: Sunday 11 January 2015 17:40
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: how to read value from web page

Post by RayAmsterdam » Wednesday 31 January 2018 20:34

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: 11
Joined: Thursday 10 May 2018 10:14
Target OS: Raspberry Pi
Domoticz version: V8.153
Location: Oss The Netherlands
Contact:

Re: how to read value from web page

Post by jackrobijn » Thursday 10 May 2018 11:48

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: 11
Joined: Thursday 10 May 2018 10:14
Target OS: Raspberry Pi
Domoticz version: V8.153
Location: Oss The Netherlands
Contact:

Re: how to read value from web page

Post by jackrobijn » Friday 11 May 2018 10:45

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

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests