Page 1 of 1

Possible to get python value into a sensor

Posted: Sunday 19 May 2019 23:46
by Thuis
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.

Re: Possible to get python value into a sensor

Posted: Monday 20 May 2019 0:35
by HvdW
Search for post or wiki like this:

Code: Select all

urllib.urlopen("http://192.168.2.1:8080/json.htm?type=command&param=switchlight&idx=158&switchcmd=Off")
You'll have to change param, idx and find something for the switchcmd.

Hope this helps you find your way.

Re: Possible to get python value into a sensor

Posted: Monday 20 May 2019 10:16
by alanlsmith
This snippet should help:

Code: Select all

#!/usr/bin/python
###
import requests
###
#rest of code
###
# Parse URL
url = 'http://<DOMOTICZ_IP>:<PORT>/json.htm?type=command&param=udevice&idx=<YOURTEXTDEVICEIDX>&nvalue=0&svalue='+str(<YOURVALUE>)'
# Send data to Domoticz device
r = requests.get(url)
Obviously change to add your numbers, etc.

Re: Possible to get python value into a sensor

Posted: Monday 20 May 2019 20:41
by Thuis
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