how to update value in Domoticz??

Python and python framework

Moderator: leecollings

Post Reply
ironrider
Posts: 11
Joined: Saturday 13 February 2016 15:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

how to update value in Domoticz??

Post by ironrider »

Hi all,
i am using a "particulate matter" software from here : https://zefanjas.de/wie-man-feinstaub-m ... ssen-kann/.
I want to send the PM2.5 data to a dummy (custom sensor).
I know that the PM2.5 value is in the 'values[0]' variable, but i don't know how to update my custom sensor in domoticz.
Maybe someone can help me a bit with this problem.
Thanks in advance.

Here is the code

Code: Select all

if __name__ == "__main__":
    while True:
        cmd_set_sleep(0)
        cmd_set_mode(1);
        for t in range(15):
            values = cmd_query_data();
            if values is not None:
               print("PM 2.5: ", values[0], ", PM10: ", values[1]) ######## Here is the Values[0] ###################
               time.sleep(2)
        # open stored data
        with open('/var/www/html/aqi.json') as json_data:
            data = json.load(json_data)

        # check if length is more than 100 and delete first element
        if len(data) > 100:
            data.pop(0)

        # append new values
        data.append({'pm25': values[0], 'pm10': values[1], 'time': time.strftime("%d.%m.%Y %H:%M:%S")})

        # save it
        with open('/var/www/html/aqi.json', 'w') as outfile:
            json.dump(data, outfile)

	urllib.urlopen('http://192.168.178.83:8080/json.htm?type=command&param=udevice&idx=1&nvalue=0&svalue= (values[0])')
	 #######  Here i want  to update my custom sensor ############	

        print("Going to sleep for 5min...")
        cmd_set_mode(0);
        cmd_set_sleep()
        time.sleep(300)
User avatar
cyberclwn
Posts: 103
Joined: Thursday 20 August 2015 22:53
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: The Netherlands
Contact:

Re: how to update value in Domoticz??

Post by cyberclwn »

Hey,

Did you read the wiki?
https://www.domoticz.com/wiki/Domoticz_ ... .2Fsensors

I found it very helpful.
3xPi 2B (Domoticz "live", Domoticz "sandbox", PhotoFrame)
RFXCom433(E), KaKu, Oregon Scientific, Keyes 2-relay, Logitech Media Server, MiLight, Smartwares heating controller(2x), IR Send/Receive, Keyes PIR, XH-M131 DuskSensor, DHT22/11
ironrider
Posts: 11
Joined: Saturday 13 February 2016 15:27
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: how to update value in Domoticz??

Post by ironrider »

Thanks for your fast answer,

i did read the wiki, but there is no example about sending the value of a variable.
Joerg99
Posts: 6
Joined: Thursday 08 March 2018 13:35
Target OS: Windows
Domoticz version:
Contact:

Re: how to update value in Domoticz??

Post by Joerg99 »

Good day I don't know if I found the right topic here. I have the following problem, I would like to control a relay via the temperature sensor. I have integrated a KMT DS1820 via a virtual dummy sensor in Domoticz on the LAN. I see the tempering and they are also updated. However, I cannot use them to activate in an event. What am I doing wrong?
SweetPants

Re: how to update value in Domoticz??

Post by SweetPants »

Joerg99 wrote: Tuesday 13 March 2018 18:36 Good day I don't know if I found the right topic here. I have the following problem, I would like to control a relay via the temperature sensor. I have integrated a KMT DS1820 via a virtual dummy sensor in Domoticz on the LAN. I see the tempering and they are also updated. However, I cannot use them to activate in an event. What am I doing wrong?
Hijacking an existing threat will probably not result in an answer on your question.
Clem
Posts: 4
Joined: Thursday 15 March 2018 10:20
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: how to update value in Domoticz??

Post by Clem »

ironrider wrote: Monday 12 March 2018 18:57 i did read the wiki, but there is no example about sending the value of a variable.
Hi @ironrider ,
What do you mean by "value of a variable"?
The link provided by @cyberclwn shows you examples of exactly how to send/update the value of a given device.
knielen
Posts: 46
Joined: Sunday 10 September 2017 9:45
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: how to update value in Domoticz??

Post by knielen »

I'm struggeling with the same issue. Were you able to find a solution.

The wiki shows how to send a fixed value, but not how to send a variable.

edit: with some help I found the solution. Here is an example with an energy meter:

Code: Select all

Total = "http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=321&nvalue=0&svalue=" .. PowerConsumption .. ";" .. EnergyConsumption;
os.execute('curl "' .. Total .. '"');
I had to split the message and create an in between solution first, this because concatenation ruined the message at first.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest