Python uservariable not updated problem

Python and python framework

Moderator: leecollings

Post Reply
boggiz
Posts: 46
Joined: Thursday 07 March 2019 11:40
Target OS: NAS (Synology & others)
Domoticz version: 2024.4
Location: France
Contact:

Python uservariable not updated problem

Post 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
NAS Syno DS718+ with 12Go ram
RFXtrx433XL v1044 with 3dBi antenna
Domoticz 2024.4 on Docker
TFA rain gauge, 4 ways automatic watering program, LINKY consumption, waterflow counter
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Python uservariable not updated problem

Post 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)
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
habahabahaba
Posts: 233
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Python uservariable not updated problem

Post by habahabahaba »

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest