Page 1 of 1

how to update value in Domoticz??

Posted: Monday 12 March 2018 18:18
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)

Re: how to update value in Domoticz??

Posted: Monday 12 March 2018 18:23
by cyberclwn
Hey,

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

I found it very helpful.

Re: how to update value in Domoticz??

Posted: Monday 12 March 2018 18:57
by ironrider
Thanks for your fast answer,

i did read the wiki, but there is no example about sending the value of a variable.

Re: how to update value in Domoticz??

Posted: Tuesday 13 March 2018 18:36
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?

Re: how to update value in Domoticz??

Posted: Tuesday 13 March 2018 19:00
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.

Re: how to update value in Domoticz??

Posted: Thursday 15 March 2018 11:56
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.

Re: how to update value in Domoticz??

Posted: Thursday 29 August 2019 14:44
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.