Accessing User Variables using internal Python Script
Moderator: leecollings
-
- Posts: 6
- Joined: Sunday 11 November 2018 17:15
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Accessing User Variables using internal Python Script
Really thankful that I encountered the internal Python(3) scripting possibility with the (new) DomoticsEvents library.
Currently I am rewriting my LUA scripts to internal Python3 scipts but now I'm stuck because I cannot find how to acces the Domoticz (global) user variables using the internal Python scripting.
There does not seem to be much help info (WIKI?) on the current possibilities of the DomoticzEvents library for Python3 so is there anybody who can help me in how to access my Domoticz User variables or any other way for using global variables with internal Python scripting?
Carlo
Currently I am rewriting my LUA scripts to internal Python3 scipts but now I'm stuck because I cannot find how to acces the Domoticz (global) user variables using the internal Python scripting.
There does not seem to be much help info (WIKI?) on the current possibilities of the DomoticzEvents library for Python3 so is there anybody who can help me in how to access my Domoticz User variables or any other way for using global variables with internal Python scripting?
Carlo
Re: Accessing User Variables using internal Python Script
You can use the json/API from Domoticz: https://www.domoticz.com/wiki/Domoticz_ ... _variables with curl or urllib.request.
I use these calls in a Python Domoticz API. Look here for more ideas: https://github.com/Xorfor/Domoticz-API/ ... erVariable
I use these calls in a Python Domoticz API. Look here for more ideas: https://github.com/Xorfor/Domoticz-API/ ... erVariable
-
- Posts: 6
- Joined: Sunday 11 November 2018 17:15
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Accessing User Variables using internal Python Script
Thanks Xorfor, gonna have a look at this. Never used these requests before so this is going to be exciting.
-
- Posts: 45
- Joined: Friday 23 February 2018 20:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: France
- Contact:
Re: Accessing User Variables using internal Python Script
Xorfor
Would you have an example or several on how to implement user variable api in a script.?
I tried but with no success.
TX
Antoine
Would you have an example or several on how to implement user variable api in a script.?
I tried but with no success.
TX
Antoine
-
- Posts: 45
- Joined: Friday 23 February 2018 20:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: France
- Contact:
Re: Accessing User Variables using internal Python Script
Me again,
In my script I have these error messages:
In my script I have these error messages:
Code: Select all
2019-04-29 16:54:00.177 Error: (VMC-W2) 'onStart' failed 'AttributeError':''NoneType' object has no attribute 'api''.
2019-04-29 16:54:00.177 Error: (VMC-W2) ----> Line 310 in /home/pi/domoticz/plugins/DrexelRead/plugin.py, function onStart
2019-04-29 16:54:00.177 Error: (VMC-W2) ----> Line 103 in /home/pi/domoticz/plugins/DrexelRead/plugin.py, function onStart
2019-04-29 16:54:00.177 Error: (VMC-W2) ----> Line 50 in /usr/lib/python3.5/DomoticzAPI/uservariable.py, function __init__
Re: Accessing User Variables using internal Python Script
@Tonio16
An example of a script can be found in tests directory: https://github.com/Xorfor/Domoticz-API/ ... ariable.py
If you still have problems, you can send me the plugin.py, and I will take a look.
Meanwhile I will try to make a plugin.py example for uservariables
An example of a script can be found in tests directory: https://github.com/Xorfor/Domoticz-API/ ... ariable.py
If you still have problems, you can send me the plugin.py, and I will take a look.
Meanwhile I will try to make a plugin.py example for uservariables
Re: Accessing User Variables using internal Python Script
I have added an example of a plugin using Uservariables from https://github.com/Xorfor/Domoticz-API. Please look at https://github.com/Xorfor/Domoticz-API/ ... riables.py. What I added was:
1. 21: import DomoticzAPI as dom
2. 36: __init__ - initialize self.__server
2. 60-70: onStart - initialize and create Uservariable
3. 88-92: onHeartbeat - Some debugging information and set the value of the Uservariable
If you look at Setup -> More Options -> User variables, you will find the uservariable `API Test Uservariable` with a value which will change every 10 seconds.
Please be aware that DomoticzAPI is still a beta version! I am still looking for more functionality and optimization.
1. 21: import DomoticzAPI as dom
2. 36: __init__ - initialize self.__server
2. 60-70: onStart - initialize and create Uservariable
3. 88-92: onHeartbeat - Some debugging information and set the value of the Uservariable
If you look at Setup -> More Options -> User variables, you will find the uservariable `API Test Uservariable` with a value which will change every 10 seconds.
Please be aware that DomoticzAPI is still a beta version! I am still looking for more functionality and optimization.
-
- Posts: 45
- Joined: Friday 23 February 2018 20:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: France
- Contact:
Re: Accessing User Variables using internal Python Script
TX, I will try tomorrow.
Antoine
Antoine
-
- Posts: 45
- Joined: Friday 23 February 2018 20:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: France
- Contact:
Re: Accessing User Variables using internal Python Script
Ok, I launched your script without anymodification and I have these errors:
I am using the last stable of Domotciz, 4.9700. Should I switch to a beta one?
Do I have to change or take care of something special in my parameters?
I have the same error line in my tries: 2019-04-30 17:28:30.492 Error: (test) ----> Line 50 in /usr/lib/python3.5/DomoticzAPI/uservariable.py, function __init__
Regards
Antoine
Code: Select all
2019-04-30 17:28:30.439 Status: (test) Initialized version 1.0.0, author 'Xorfor'
2019-04-30 17:28:30.492 Error: (test) 'onStart' failed 'AttributeError':''NoneType' object has no attribute 'api''.
2019-04-30 17:28:30.492 Error: (test) ----> Line 152 in /home/pi/domoticz/plugins/UserVarRW/plugin.py, function onStart
2019-04-30 17:28:30.492 Error: (test) ----> Line 65 in /home/pi/domoticz/plugins/UserVarRW/plugin.py, function onStart
2019-04-30 17:28:30.492 Error: (test) ----> Line 50 in /usr/lib/python3.5/DomoticzAPI/uservariable.py, function __init__
2019-04-30 17:28:39.962 Error: (test) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute '_BasePlugin__var''.
2019-04-30 17:28:39.962 Error: (test) ----> Line 136 in /home/pi/domoticz/plugins/UserVarRW/plugin.py, function onHeartbeat
2019-04-30 17:28:39.962 Error: (test) ----> Line 89 in /home/pi/domoticz/plugins/UserVarRW/plugin.py, function onHeartbeat
Do I have to change or take care of something special in my parameters?
I have the same error line in my tries: 2019-04-30 17:28:30.492 Error: (test) ----> Line 50 in /usr/lib/python3.5/DomoticzAPI/uservariable.py, function __init__
Regards
Antoine
Re: Accessing User Variables using internal Python Script
@Tonio16,
Yes, please update to the latest beta version.
If you work with Python plugins, it is better to stay on the latest beta. Since the latest stable version, some important improvements are made.
Yes, please update to the latest beta version.
If you work with Python plugins, it is better to stay on the latest beta. Since the latest stable version, some important improvements are made.
-
- Posts: 45
- Joined: Friday 23 February 2018 20:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: France
- Contact:
Re: Accessing User Variables using internal Python Script
Ok, I update to beta, to the lastest Domoticz-API but I have still the same error:
With my poorly understanding, it looks so that the uservariable.py is not dealing the api.py.
Do I have to install other API than yours?
By installing some other python plugins, I discovered something strange on my installation of librairies, for example with requests:
$ sudo pip3 show requests
Name: requests
Version: 2.21.0
Summary: Python HTTP for Humans.
Home-page: http://python-requests.org
Author: Kenneth Reitz
Author-email: [email protected]
License: Apache 2.0
Location: /usr/local/lib/python3.5/dist-packages/requests-2.21.0-py3.5.egg
Requires: certifi, chardet, idna, urllib3
After uninstall and install it looks normal: Location: /usr/local/lib/python3.5/dist-packages
For your Domoticz-API, I hav:
sudo pip3 show DomoticzAPI
Name: DomoticzAPI
Version: 0.13.1b0
Summary: Domoticz API for Python
Home-page: https://github.com/Xorfor/Domoticz-API/
Author: Xorfor
Author-email: [email protected]
License: MIT License
Location: /usr/lib/python3.5
Requires:
Antoine
Code: Select all
2019-04-30 20:26:29.451 Status: Python EventSystem: Initalizing event module.
2019-04-30 20:26:29.451 Status: EventSystem: Started
2019-04-30 20:26:29.451 Status: EventSystem: Queue thread started...
2019-04-30 20:26:29.354 Error: (test) 'onStart' failed 'AttributeError':''NoneType' object has no attribute 'api''.
2019-04-30 20:26:29.354 Error: (test) ----> Line 152 in '/home/pi/domoticz/plugins/UserVarRW/plugin.py', function onStart
2019-04-30 20:26:29.355 Error: (test) ----> Line 65 in '/home/pi/domoticz/plugins/UserVarRW/plugin.py', function onStart
2019-04-30 20:26:29.355 Error: (test) ----> Line 50 in '/usr/lib/python3.5/DomoticzAPI/uservariable.py', function __init__
2019-04-30 20:26:38.867 Error: (test) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute '_BasePlugin__var''.
2019-04-30 20:26:38.867 Error: (test) ----> Line 136 in '/home/pi/domoticz/plugins/UserVarRW/plugin.py', function onHeartbeat
2019-04-30 20:26:38.868 Error: (test) ----> Line 89 in '/home/pi/domoticz/plugins/UserVarRW/plugin.py', function onHeartbeat
2019-04-30 20:26:50.264 Error: (test) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute '_BasePlugin__var''.
2019-04-30 20:26:50.266 Error: (test) ----> Line 136 in '/home/pi/domoticz/plugins/UserVarRW/plugin.py', function onHeartbeat
2019-04-30 20:26:50.266 Error: (test) ----> Line 89 in '/home/pi/domoticz/plugins/UserVarRW/plugin.py', function onHeartbeat
Do I have to install other API than yours?
By installing some other python plugins, I discovered something strange on my installation of librairies, for example with requests:
$ sudo pip3 show requests
Name: requests
Version: 2.21.0
Summary: Python HTTP for Humans.
Home-page: http://python-requests.org
Author: Kenneth Reitz
Author-email: [email protected]
License: Apache 2.0
Location: /usr/local/lib/python3.5/dist-packages/requests-2.21.0-py3.5.egg
Requires: certifi, chardet, idna, urllib3
After uninstall and install it looks normal: Location: /usr/local/lib/python3.5/dist-packages
For your Domoticz-API, I hav:
sudo pip3 show DomoticzAPI
Name: DomoticzAPI
Version: 0.13.1b0
Summary: Domoticz API for Python
Home-page: https://github.com/Xorfor/Domoticz-API/
Author: Xorfor
Author-email: [email protected]
License: MIT License
Location: /usr/lib/python3.5
Requires:
Antoine
-
- Posts: 45
- Joined: Friday 23 February 2018 20:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: France
- Contact:
Re: Accessing User Variables using internal Python Script
last point today.
I tried to install the iCal plugin and I had this message:
2019-04-30 22:12:10.128 Error: (test) Error sending command to domoticz : type=command¶m=getuservariables
2019-04-30 22:12:10.128 Error: (test) Erreur to execute get user variables
I tried json links directly in Firefoy and it worked: create, modify, read.
Antoine
I tried to install the iCal plugin and I had this message:
2019-04-30 22:12:10.128 Error: (test) Error sending command to domoticz : type=command¶m=getuservariables
2019-04-30 22:12:10.128 Error: (test) Erreur to execute get user variables
I tried json links directly in Firefoy and it worked: create, modify, read.
Antoine
Re: Accessing User Variables using internal Python Script
So probably something with your installation? It looks not related to Python or the plugins.
On which platform/version is Domoticz installed?
Did you a default Domoticz install?
Can you ping to localhost?
Are you using the default port 8080?
Etc...
On which platform/version is Domoticz installed?
Did you a default Domoticz install?
Can you ping to localhost?
Are you using the default port 8080?
Etc...
-
- Posts: 45
- Joined: Friday 23 February 2018 20:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: France
- Contact:
Re: Accessing User Variables using internal Python Script
Hello
Just to be sure. Is it normal that your plugin is using this path: Location: /usr/lib/python3.5
and not Location: /usr/lib/python3.5/dist-packages like other ?
I missed your answer Xorfor.
I am on a Raspberry Pi 3+. I am regularly doing some apt-get update upgrade, so it should be up to date.
Domoticz is a default install.
Ping localhost seems ok.
- Spoiler: show
Here the debug:
Code: Select all
2019-05-05 14:11:10.325 Status: (test) Entering work loop.
2019-05-05 14:11:10.325 Status: (test) Initialized version 1.0.0, author 'Xorfor'
2019-05-05 14:11:10.327 Error: (test) 'onStart' failed 'AttributeError':''NoneType' object has no attribute 'api''.
2019-05-05 14:11:10.327 Error: (test) ----> Line 156 in '/home/pi/domoticz/plugins/UserVarRW/plugin.py', function onStart
2019-05-05 14:11:10.327 Error: (test) ----> Line 69 in '/home/pi/domoticz/plugins/UserVarRW/plugin.py', function onStart
2019-05-05 14:11:10.327 Error: (test) ----> Line 50 in '/usr/lib/python3.5/DomoticzAPI/uservariable.py', function __init__
2019-05-05 14:11:20.327 (test) Pushing 'onHeartbeatCallback' on to queue
2019-05-05 14:11:20.348 (test) Processing 'onHeartbeatCallback' message
2019-05-05 14:11:20.348 (test) Calling message handler 'onHeartbeat'.
2019-05-05 14:11:20.349 (test) onHeartbeat called
2019-05-05 14:11:20.349 (test) self.__server: Server("localhost", "8080"): False
2019-05-05 14:11:20.349 Error: (test) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute '_BasePlugin__var''.
2019-05-05 14:11:20.349 Error: (test) ----> Line 140 in '/home/pi/domoticz/plugins/UserVarRW/plugin.py', function onHeartbeat
2019-05-05 14:11:20.349 Error: (test) ----> Line 93 in '/home/pi/domoticz/plugins/UserVarRW/plugin.py', function onHeartbeat
2019-05-05 14:11:30.328 (test) Pushing 'onHeartbeatCallback' on to queue
2019-05-05 14:11:30.367 (test) Processing 'onHeartbeatCallback' message
2019-05-05 14:11:30.367 (test) Calling message handler 'onHeartbeat'.
2019-05-05 14:11:30.367 (test) onHeartbeat called
2019-05-05 14:11:30.367 (test) self.__server: Server("localhost", "8080"): False
2019-05-05 14:11:30.368 Error: (test) 'onHeartbeat' failed 'AttributeError':''BasePlugin' object has no attribute '_BasePlugin__var''.
2019-05-05 14:11:30.368 Error: (test) ----> Line 140 in '/home/pi/domoticz/plugins/UserVarRW/plugin.py', function onHeartbeat
2019-05-05 14:11:30.368 Error: (test) ----> Line 93 in '/home/pi/domoticz/plugins/UserVarRW/plugin.py', function onHeartbeat
Antoine
Re: Accessing User Variables using internal Python Script
Hmmm. /usr/lib/python3.5 is one of the directories in the path for Python. You can try:
or try on your RPi:
Code: Select all
sudo pip3 install git+git://github.com/Xorfor/Domoticz-API.git -t /usr/lib/python3.5/dist-packages
Code: Select all
curl 'http://localhost:8080/json.htm?type=command¶m=getSunRiseSet'
-
- Posts: 45
- Joined: Friday 23 February 2018 20:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: France
- Contact:
Re: Accessing User Variables using internal Python Script
Hello Xorfor
Tx a lot to help me.
If I do the curl, I have this message:
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
With sudo, it is the same.
With the IP address, 192.168.x.x, instead of localhost or 127.0.0.1, it works.
I am running Domoticz on a SSD and not a SD-card, could it be the reason ?
Regards
Antoine
Tx a lot to help me.
If I do the curl, I have this message:
<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>
With sudo, it is the same.
With the IP address, 192.168.x.x, instead of localhost or 127.0.0.1, it works.
I am running Domoticz on a SSD and not a SD-card, could it be the reason ?
Regards
Antoine
Re: Accessing User Variables using internal Python Script
Antoine,
Please check your setting Local Networks (no username/password). I guess that you have the value 192.168.*.*, or something like this. Please add 128.0.0.*, so that you get 192.168.*.*;128.0.0.*.
What you also can do is to change /home/pi/domoticz/plugins/UserVarRW/plugin.py:
to
Please check your setting Local Networks (no username/password). I guess that you have the value 192.168.*.*, or something like this. Please add 128.0.0.*, so that you get 192.168.*.*;128.0.0.*.
What you also can do is to change /home/pi/domoticz/plugins/UserVarRW/plugin.py:
Code: Select all
...
def __init__(self):
self.__runAgain = 0
self.__server = dom.Server()
...
Code: Select all
...
def __init__(self):
self.__runAgain = 0
self.__server = dom.Server("<ip adress Domoticz server>", "8080")
...
-
- Posts: 45
- Joined: Friday 23 February 2018 20:38
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: France
- Contact:
Re: Accessing User Variables using internal Python Script
Hello Xorfor
I looked to my parameters and the IP address range was false, a "," instead of a ";" between 192.168.*.* and 127.0.0.*
After my correction, the json command is working but not the plugins.
With this command, the json is also not working.
I understand well that localhost and 127.0.0.1 shoud behave the same here?
With this setting in the plugin, it's working.
Thanks a lot for your support. I hope that it will somehow help you for the développement of this plugin.
Antoine
I looked to my parameters and the IP address range was false, a "," instead of a ";" between 192.168.*.* and 127.0.0.*
After my correction, the json command is working but not the plugins.
Code: Select all
curl 'http://127.0.0.1:8080/json.htm?type=command¶m=getSunRiseSet'
Code: Select all
curl 'http://localhost:8080/json.htm?type=command¶m=getSunRiseSet'
With this setting in the plugin, it's working.
Code: Select all
def __init__(self):
self.__runAgain = 0
self.__server = dom.Server("192.168.x.z","8080")
Antoine
Who is online
Users browsing this forum: No registered users and 1 guest