I have a sp3s and i can get it on and off with python, using a virtual switch with script://
Now the python script also can give the energy reading. My question is, how do i get script:// into a sensor that displays the value of the python script.
The python script gives back a value, but i do not know how to put this into a virtual text or energy meter.
I did search for examples in the wiki but i do not understand how to get the value output that i see on the pi command line into a sensor, please help.
Any ideas, tips or examples ?
Thank you in advance.
Possible to get python value into a sensor Topic is solved
Moderator: leecollings
- Thuis
- Posts: 268
- Joined: Tuesday 11 September 2018 11:36
- Target OS: Linux
- Domoticz version: Beta
- Location: The Netherlands
- Contact:
Possible to get python value into a sensor
I Love Domoticz ! And the community around it :-)
-
- Posts: 593
- Joined: Sunday 01 November 2015 22:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.2
- Location: Twente
- Contact:
Re: Possible to get python value into a sensor
Search for post or wiki like this:
You'll have to change param, idx and find something for the switchcmd.
Hope this helps you find your way.
Code: Select all
urllib.urlopen("http://192.168.2.1:8080/json.htm?type=command¶m=switchlight&idx=158&switchcmd=Off")
Hope this helps you find your way.
Bugs bug me.
-
- Posts: 132
- Joined: Monday 07 August 2017 17:17
- Target OS: Linux
- Domoticz version: Latest β
- Location: Near London (Saaarf!)
- Contact:
Re: Possible to get python value into a sensor
This snippet should help:
Obviously change to add your numbers, etc.
Code: Select all
#!/usr/bin/python
###
import requests
###
#rest of code
###
# Parse URL
url = 'http://<DOMOTICZ_IP>:<PORT>/json.htm?type=command¶m=udevice&idx=<YOURTEXTDEVICEIDX>&nvalue=0&svalue='+str(<YOURVALUE>)'
# Send data to Domoticz device
r = requests.get(url)
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.
- Thuis
- Posts: 268
- Joined: Tuesday 11 September 2018 11:36
- Target OS: Linux
- Domoticz version: Beta
- Location: The Netherlands
- Contact:
Re: Possible to get python value into a sensor
Thanks for your answers, but i do this on the cli:
/home/domo/python-broadlink/broadlink_cli --type 0x947a --host 1xx.x.x.106 --mac 34xxxx9xxx5x --energy
And i get this value back in the cli: 12.56
So how do i get this value in to a virtual sensor. I just do not know.
I guess i can not do <YOURVALUE> as script:///home/domo/python-broadlink/broadlink_cli --type 0x947a --host 1xx.x.x.106 --mac 34xxxx9xxx5x --energy
or maybe something like,
myvar= "//home/domo/python-broadlink/broadlink_cli --type 0x947a --host 1xx.x.x.106 --mac 34xxxx9xxx5x --energy" :real;
Maybe this is stupid, but i think there should be a way? But what is it ? Is it possible?
I am just trying different things, but keep getting SyntaxError: EOL while scanning string literal
I see it is not a string, but a floating point. So now i am just searching the internet, how to get svalue+str to ?? fvalue+float ?? or something like that. I am just guessing how this would work. Isn't it obvious ? HA
/home/domo/python-broadlink/broadlink_cli --type 0x947a --host 1xx.x.x.106 --mac 34xxxx9xxx5x --energy
And i get this value back in the cli: 12.56
So how do i get this value in to a virtual sensor. I just do not know.
I guess i can not do <YOURVALUE> as script:///home/domo/python-broadlink/broadlink_cli --type 0x947a --host 1xx.x.x.106 --mac 34xxxx9xxx5x --energy
or maybe something like,
myvar= "//home/domo/python-broadlink/broadlink_cli --type 0x947a --host 1xx.x.x.106 --mac 34xxxx9xxx5x --energy" :real;
Maybe this is stupid, but i think there should be a way? But what is it ? Is it possible?
I am just trying different things, but keep getting SyntaxError: EOL while scanning string literal
I see it is not a string, but a floating point. So now i am just searching the internet, how to get svalue+str to ?? fvalue+float ?? or something like that. I am just guessing how this would work. Isn't it obvious ? HA
I Love Domoticz ! And the community around it :-)
Who is online
Users browsing this forum: No registered users and 1 guest