Sensor Values for PID

Python and python framework

Moderator: leecollings

Post Reply
JasperJackson
Posts: 6
Joined: Saturday 30 September 2017 10:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Sensor Values for PID

Post by JasperJackson »

Hello everybody!

I'm a firmware engineer in the the HVAC working with C and C++ on ARM processors most of the time, i'm new to Python.

I'm working on a domoticz multi purpose PID control plugin which uses Domoticz Sensorvalues and Switches to control actuators.

I'm all up and running with a RaspPi, working 1-Wire sensors and a working plugin framework :)

However I cannot find a way in your forums to directly interface with domoticz devices. In my python script i need the temperature of a 1-wire sensor, the only way I can find now is to use the JSON interface which seems a bit of a long way around. Is there some sort of domoticz.devices[Idx].nValue i can use? I mean, i understand that children are only allowed to talk to their parents, but maybe there is a way.

The other possibility would be to let the plugin create devices which in turn need to be linked to domoticz sensors which is a bit of a hassle as well.

Any help would be appreciated.

Regards!

Jasper Jackson

Using JSON through a http interface means that my password is exposed to the whole internet??
JasperJackson
Posts: 6
Joined: Saturday 30 September 2017 10:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sensor Values for PID

Post by JasperJackson »

Is there anyone here willing to help??
febalci
Posts: 331
Joined: Monday 03 July 2017 19:58
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Sensor Values for PID

Post by febalci »

In Python plugins you interact like this:

Code: Select all

def UpdateDevice(Unit, nValue, sValue):
    # Make sure that the Domoticz device still exists (they can be deleted) before updating it 
    if (Unit in Devices):
        if (Devices[Unit].nValue != nValue) or (Devices[Unit].sValue != sValue):
            Devices[Unit].Update(nValue, str(sValue))
            Domoticz.Log("Update "+str(nValue)+":'"+str(sValue)+"' ("+Devices[Unit].Name+")")
return
Unit is the IDX value of the device.

Also in Python scripts:

Code: Select all

for name, device in domoticz.devices.items():
  domoticz.log("device", name, "is", "on" if device.is_on() else "off")
  if device.is_off():
      domoticz.log("could turn it on in 3 seconds")
      #device.on(after=3)
for name, value in user_variables.items():
  domoticz.log("var", name, "has value", value)
 
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Sensor Values for PID

Post by Dnpwwo »

@febalci,

Have a look at the Python samples that ship with Domoticz, they are also here: https://github.com/domoticz/domoticz/tr ... s/examples
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
JasperJackson
Posts: 6
Joined: Saturday 30 September 2017 10:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sensor Values for PID

Post by JasperJackson »

Thanks for the replies!

I tried the above functions before already and it didn't work. I found out that i have a problem with my python setup as the sample script is executed but files an error on the console when using domoticz.log, the length of the devices array is 0. So i tried a fresh install (jessie) and am now facing a illegal instruction when starting domoticz. So i keep trying. I installed the python3 and python3-dev using apt-get.

Regards,

Jasper Jackson

This will only show up in the shell where you start domoticz
Traceback (most recent call last):
File "<string>", line 67, in <module>
NameError: name 'Domoticz' is not defined
JasperJackson
Posts: 6
Joined: Saturday 30 September 2017 10:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sensor Values for PID

Post by JasperJackson »

Ok, i got the Python plugins working now, it turned out i was using the wrong examples, there obvousliy has been some API change.

https://github.com/domoticz/domoticz/bl ... emplate.py
This one works.

I'm facing one small problem now,

Domoticz.Log(str(len(Devices)))

returns 0, so it makes it look like there are no devices present. But there are 19 devices present in the system. Am i Missing something here?

Thanks

Jasper
JasperJackson
Posts: 6
Joined: Saturday 30 September 2017 10:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sensor Values for PID

Post by JasperJackson »

Dnpwwo wrote: Tuesday 10 October 2017 23:18 @febalci,

Have a look at the Python samples that ship with Domoticz, they are also here: https://github.com/domoticz/domoticz/tr ... s/examples
Link is dead
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Sensor Values for PID

Post by Dnpwwo »

@JasperJackson,

That branch has been merged, check the main development branch: https://github.com/domoticz/domoticz/tr ... s/examples
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
JasperJackson
Posts: 6
Joined: Saturday 30 September 2017 10:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Sensor Values for PID

Post by JasperJackson »

Thanks, I'm using that one at the moment,

I still got the Feeling that the Domoticz.Devices module only has the Plugin Private devices in it as it is always 0 in my system. Is there a way to directly control or read values from other devices in Domoticz plugins without the need of JSON?

Thank you!

Jasper
Post Reply

Who is online

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