How to get value from sensors
Posted: Sunday 03 January 2021 12:36
I want to display sensor values ​​but cannot access these values. I have created a script (python) for connecting Raspberry with Telegram and this is where I'm going to display the data, but first I need to download it somehow. So I'm using code https://www.domoticz.com/wiki/Python_-_ ... python3.29 but it doesn't work for me.
Code of file "test1.py":
IP address is correct. When I check the URL in the browser than I get a result.
When i run the code i get something like that:
Some details:
RaspberryPi 4B
Python3 version 3.7.3
Domoticz version 2020.2
Code of file "test1.py":
Code: Select all
import json
import urllib.request, urllib.error, urllib.parse
domoticzurl = 'http://192.168.1.210:8080/json.htm?type=devices&rid=20'
def domoticzrequest (url):
request = urllib.request.Request(url)
response = urllib.request.urlopen(request)
return response.read()
json_object = json.loads(domoticzrequest(domoticzurl))
if json_object["status"] == "OK":
temp = json_object["result"][0]['Temp']
print(temp)
When i run the code i get something like that:
- Spoiler: show
Some details:
RaspberryPi 4B
Python3 version 3.7.3
Domoticz version 2020.2