Page 1 of 1

Python uservariable not updated problem

Posted: Tuesday 28 May 2024 19:49
by boggiz
Hello all,
I have a problem updating an uservariable with python in Domoticz IDE.
In the python script below the New value is still not correct after 30 seconds of waiting!

Code: Select all

import DomoticzEvents as DE
import requests  
import time as time

if DE.changed_device_name == "Test Python": 
    New= 35050
    url= "http://192.168.0.45:18080/json.htm?type=command&param=updateuservariable&vname=Test entier&vtype=0&vvalue=" + str(New)
    CLE64 = {"Authorization" : "Basic RG9tb0JvZ2dpeTUwRFMhYWZ5MTk1MA=="}
    try:    
        rc = requests.get(url, timeout=(1,1), headers= CLE64)   # sans AUT erreur 401
        print(rc.raise_for_status())
    except requests.exceptions.RequestException as err:
        print ("R-OOps: Something Else",err)
    except requests.exceptions.HTTPError as errh:
        print ("R-Http Error:",errh)
    except requests.exceptions.ConnectionError as errc:
        print ("R-Error Connecting:",errc)
    except requests.exceptions.Timeout as errt:
        print ("R-Timeout Error:",errt)
        
    time.sleep(30)
    print ("Nouvelle valeur: " + DE.user_variables["Test entier"])
    DE.Log("Nouvelle valeur: " + DE.user_variables["Test entier"])
When I manually refresh the User Variable page the correct value is displayed.

I think it's an update problem but how to do it in Python?
Thanks in advance

Re: Python uservariable not updated problem

Posted: Tuesday 28 May 2024 22:23
by waltervl
I would advise you to switch to Dzvents if this is your first script in Domoticz.
I also would advise you to exclude API requests from the server from logging in (settings security: Allow Basic HTTP Authorization and Trusted Network)

Re: Python uservariable not updated problem

Posted: Wednesday 29 May 2024 7:32
by habahabahaba