Enable/disable timer from events / LUA script Topic is solved
Moderators: leecollings, remb0
-
- Posts: 6
- Joined: Wednesday 02 October 2013 15:53
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Enable/disable timer from events / LUA script
Option to enable / disable a (set of) timer(s) for a switch/device from within events (blockly) or via a LUA script would be very welcome.
Screenshot to illustrate:
Screenshot to illustrate:
-
- Posts: 5
- Joined: Sunday 22 September 2013 22:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.1
- Location: Malmö, SWEDEN
- Contact:
Re: Enable/disable timer from events / LUA script
+1
Im also looking for this.
Se this post for info: http://www.domoticz.com/forum/viewtopic ... 4323#p4287
Im also looking for this.
Se this post for info: http://www.domoticz.com/forum/viewtopic ... 4323#p4287
-
- Posts: 1
- Joined: Saturday 10 October 2015 17:42
- Target OS: Linux
- Domoticz version:
- Contact:
Re: Enable/disable timer from events / LUA script
I have an Arch Linux
It works with this workaround
ENABLE
in LUA script (script_device_xxx.lua):
24 is idx
1 is Activate
then in SH script (sql.sh):
DISABLE
in LUA script:
It works with this workaround
ENABLE
in LUA script (script_device_xxx.lua):
Code: Select all
os.execute ("/opt/domoticz/scripts/sql.sh 24 1")
1 is Activate
then in SH script (sql.sh):
Code: Select all
#!/bin/bash
sqlite3 -header /opt/domoticz/domoticz.db "UPDATE SetPointTimers SET Active = $2 WHERE DeviceRowID = $1 AND Active <> $2;"
in LUA script:
Code: Select all
os.execute ("/opt/domoticz/scripts/sql.sh 24 0")
Re: Enable/disable timer from events / LUA script
Also possible on Domoticz with JSON: (since august 27 )
Enable timer:
Disable timer
Enable scene-timer
Disable scene-timer
Show all timers:
Show all scene-timers:
Have fun!
PS: Not advisable to edit the DataBase at runtime in my opinion, that why i wrote these extra JSON-calls
Enable timer:
Code: Select all
http://<ip>:<port>/json.htm?type=command¶m=enabletimer&idx=1
Code: Select all
http://<ip>:<port>/json.htm?type=command¶m=disabletimer&idx=1
Code: Select all
http://<ip>:<port>/json.htm?type=command¶m=enablescenetimer&idx=1
Code: Select all
http://<ip>:<port>/json.htm?type=command¶m=disablescenetimer&idx=1
Code: Select all
http://<ip>:<port>/json.htm?type=command¶m=gettimerlist
Code: Select all
http://<ip>:<port>/json.htm?type=command¶m=getscenetimerlist
PS: Not advisable to edit the DataBase at runtime in my opinion, that why i wrote these extra JSON-calls
-
- Posts: 6
- Joined: Sunday 17 January 2016 19:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Enable/disable timer from events / LUA script
Hi Eduard,
Could you elaborate on if and how to make these json URL's work with the blockly? I tried the setup in the image below:
It changes the state of the control variable. In the log I can see it tried to fetch the URL:
but there is no change of state in the timer list. If I try the same URL from my browser it works fine.
Help would be very much appreciated.
Casper
Could you elaborate on if and how to make these json URL's work with the blockly? I tried the setup in the image below:
It changes the state of the control variable. In the log I can see it tried to fetch the URL:
but there is no change of state in the timer list. If I try the same URL from my browser it works fine.
Help would be very much appreciated.
Casper
Re: Enable/disable timer from events / LUA script
Sorry, i can't tell you why the blockly is not working because i don't use them. I only use (bash/python) scripts to fire the json calls.
Verzonden vanaf mijn iPad met Tapatalk
Verzonden vanaf mijn iPad met Tapatalk
-
- Posts: 6
- Joined: Sunday 17 January 2016 19:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Enable/disable timer from events / LUA script
Hi Eduard,
As a complete NOOB to Domoticz (started two weeks ago) and pyton scripts could you elaborate in how to process a json call into a script?
My main intention in enabling and disabling timers is that I would like to create a "holidays" button that will activate and deactivate a set of timers that will turn lamps on and off in the house. Next to that I would also like to check the sunrise and sunset times to decide if the outdoor lamps should be turned on or not. Blockly appeared to be ideal for this, but unfortunately I cannot get it to work for me. Next to that the timer functions that can be associated to the buttons are very easy to use and versatile enough except for the problems described above.
Any help on calling the json commands in a python script is very welcome. After that I think I will be able to get it to work for me no problem.
Thanks for the help.
As a complete NOOB to Domoticz (started two weeks ago) and pyton scripts could you elaborate in how to process a json call into a script?
My main intention in enabling and disabling timers is that I would like to create a "holidays" button that will activate and deactivate a set of timers that will turn lamps on and off in the house. Next to that I would also like to check the sunrise and sunset times to decide if the outdoor lamps should be turned on or not. Blockly appeared to be ideal for this, but unfortunately I cannot get it to work for me. Next to that the timer functions that can be associated to the buttons are very easy to use and versatile enough except for the problems described above.
Any help on calling the json commands in a python script is very welcome. After that I think I will be able to get it to work for me no problem.
Thanks for the help.
Re: Enable/disable timer from events / LUA script
Here is a simple python example
Hope it get's you started!
Code: Select all
import urllib2
domoticzserver = "127.0.0.1:8080"
domoticzusername = ""
domoticzpassword = ""
base64string = base64.encodestring('%s:%s' % (domoticzusername, domoticzpassword)).replace('\n', '')
def DomoticzRequest (url):
request = urllib2.Request(url)
request.add_header("Authorization", "Basic %s" % base64string)
response = urllib2.urlopen(request)
return response.read()
url = "http://" + domoticzserver + "/json.htm?type=command¶m=enabletimer&idx=1"
DomoticzRequest(url)
- G3rard
- Posts: 669
- Joined: Wednesday 04 March 2015 22:15
- Target OS: -
- Domoticz version: No
- Location: The Netherlands
- Contact:
Re: Enable/disable timer from events / LUA script
Other possibilty is to activate the Holiday timer. This option can be found at Setup-Settings-Other-Timer Plan. When Holiday timer is actived, you can set other timers then in the default plan.clkoolen wrote:Hi Eduard,
As a complete NOOB to Domoticz (started two weeks ago) and pyton scripts could you elaborate in how to process a json call into a script?
My main intention in enabling and disabling timers is that I would like to create a "holidays" button that will activate and deactivate a set of timers that will turn lamps on and off in the house. Next to that I would also like to check the sunrise and sunset times to decide if the outdoor lamps should be turned on or not. Blockly appeared to be ideal for this, but unfortunately I cannot get it to work for me. Next to that the timer functions that can be associated to the buttons are very easy to use and versatile enough except for the problems described above.
Any help on calling the json commands in a python script is very welcome. After that I think I will be able to get it to work for me no problem.
Thanks for the help.
Not using Domoticz anymore
-
- Posts: 6
- Joined: Sunday 17 January 2016 19:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Enable/disable timer from events / LUA script
Hi Eduard,
Thanks for the script example. I got it to work with the addition of import base64.
Now I will have to make it do my desired changes.
Thanks again.
Thanks for the script example. I got it to work with the addition of import base64.
Now I will have to make it do my desired changes.
Thanks again.
-
- Posts: 6
- Joined: Sunday 17 January 2016 19:45
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Enable/disable timer from events / LUA script
Ended up creating a single script that would check a specific group is on or off.
Then depending on the state it enables or disables a set of timers by the id's.
Then depending on the state it enables or disables a set of timers by the id's.
Code: Select all
#!/usr/bin/python
import urllib2
import base64
import json
"""
General scrypt settings.
Set the appropriate username and password.
Enter the id of the group that will turn on and off the timers
Enter the ids of the timers that will be turned on and off
"""
domoticzserver = "127.0.0.1:8080"
domoticzusername = "username"
domoticzpassword = "password"
group_id = "1"
timer_ids = [1, 2]
"""
Build the encoded password string
"""
base64string = base64.encodestring('%s:%s' % (domoticzusername, domoticzpassword)).replace('\n', '')
"""
Process the url request
"""
def DomoticzRequest (url):
request = urllib2.Request(url)
request.add_header("Authorization", "Basic %s" % base64string)
response = urllib2.urlopen(request)
return response.read()
"""
Request the group and scene list.
Filter out the status of the desired group id
set the json command based on the status
"""
url = "http://" + domoticzserver + "/json.htm?type=scenes"
data = json.loads(DomoticzRequest(url))
group_info = [obj for obj in data["result"] if(obj["idx"]== group_id)]
group_status = group_info[0]["Status"]
if group_status == "Off":
json_command = "/json.htm?type=command¶m=disabletimer&idx="
else:
json_command = "/json.htm?type=command¶m=enabletimer&idx="
"""
Send the json command for all desired timer ids
"""
for id in timer_ids:
url = "http://" + domoticzserver + json_command + "%i" %id
DomoticzRequest(url)
Who is online
Users browsing this forum: No registered users and 0 guests