Page 1 of 1

Sensor Values for PID

Posted: Saturday 30 September 2017 10:17
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??

Re: Sensor Values for PID

Posted: Monday 02 October 2017 19:18
by JasperJackson
Is there anyone here willing to help??

Re: Sensor Values for PID

Posted: Sunday 08 October 2017 16:20
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)
 

Re: Sensor Values for PID

Posted: Tuesday 10 October 2017 23:18
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

Re: Sensor Values for PID

Posted: Wednesday 11 October 2017 7:19
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

Re: Sensor Values for PID

Posted: Wednesday 18 October 2017 10:43
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

Re: Sensor Values for PID

Posted: Wednesday 18 October 2017 10:43
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

Re: Sensor Values for PID

Posted: Wednesday 18 October 2017 11:01
by Dnpwwo
@JasperJackson,

That branch has been merged, check the main development branch: https://github.com/domoticz/domoticz/tr ... s/examples

Re: Sensor Values for PID

Posted: Wednesday 18 October 2017 11:07
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