Enable/disable timer from events / LUA script Topic is solved

Use this forum to discuss possible implementation of a new feature before opening a ticket.
A developer shall edit the topic title with "[xxx]" where xxx is the id of the accompanying tracker id.
Duplicate posts about the same id. +1 posts are not allowed.
Post Reply
rdebruijn
Posts: 26
Joined: Wednesday 02 October 2013 15:53
Target OS: Raspberry Pi
Domoticz version:
Contact:

Enable/disable timer from events / LUA script

Post by rdebruijn » Thursday 31 October 2013 14:31

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:

Image

Paulyoh
Posts: 19
Joined: Sunday 22 September 2013 22:21
Target OS: Raspberry Pi
Domoticz version:
Location: Malmö, SWEDEN
Contact:

Re: Enable/disable timer from events / LUA script

Post by Paulyoh » Thursday 31 October 2013 15:19

+1

Im also looking for this. :)
Se this post for info: http://www.domoticz.com/forum/viewtopic ... 4323#p4287

asdfgh1234
Posts: 1
Joined: Saturday 10 October 2015 17:42
Target OS: Linux
Domoticz version:
Contact:

Re: Enable/disable timer from events / LUA script

Post by asdfgh1234 » Saturday 10 October 2015 17:56

I have an Arch Linux

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")
24 is idx
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;"
DISABLE
in LUA script:

Code: Select all

os.execute ("/opt/domoticz/scripts/sql.sh 24 0")

User avatar
Eduard
Posts: 291
Joined: Monday 19 January 2015 10:14
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Enable/disable timer from events / LUA script

Post by Eduard » Saturday 10 October 2015 19:51

Also possible on Domoticz with JSON: (since august 27 :D )

Enable timer:

Code: Select all

http://<ip>:<port>/json.htm?type=command&param=enabletimer&idx=1
Disable timer

Code: Select all

http://<ip>:<port>/json.htm?type=command&param=disabletimer&idx=1
Enable scene-timer

Code: Select all

http://<ip>:<port>/json.htm?type=command&param=enablescenetimer&idx=1
Disable scene-timer

Code: Select all

http://<ip>:<port>/json.htm?type=command&param=disablescenetimer&idx=1
Show all timers:

Code: Select all

http://<ip>:<port>/json.htm?type=command&param=gettimerlist
Show all scene-timers:

Code: Select all

http://<ip>:<port>/json.htm?type=command&param=getscenetimerlist
Have fun!

PS: Not advisable to edit the DataBase at runtime in my opinion, that why i wrote these extra JSON-calls ;)
3x Raspberry Pi (Master, Slave & Test)
1x Test VM Windows (VS 2015)
1x Test VM Ubuntu

clkoolen
Posts: 6
Joined: Sunday 17 January 2016 20:45
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Enable/disable timer from events / LUA script

Post by clkoolen » Sunday 17 January 2016 21:02

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:
Event with json.PNG
Event with json.PNG (26.58 KiB) Viewed 4387 times
It changes the state of the control variable. In the log I can see it tried to fetch the URL:
Log.PNG
Log.PNG (9.5 KiB) Viewed 4387 times


but there is no change of state in the timer list. If I try the same URL from my browser it works fine.
Entry Timerlist.PNG
Entry Timerlist.PNG (5.05 KiB) Viewed 4387 times
Help would be very much appreciated.

Casper

User avatar
Eduard
Posts: 291
Joined: Monday 19 January 2015 10:14
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Enable/disable timer from events / LUA script

Post by Eduard » Sunday 17 January 2016 23:39

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
3x Raspberry Pi (Master, Slave & Test)
1x Test VM Windows (VS 2015)
1x Test VM Ubuntu

clkoolen
Posts: 6
Joined: Sunday 17 January 2016 20:45
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Enable/disable timer from events / LUA script

Post by clkoolen » Monday 18 January 2016 17:52

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.

User avatar
Eduard
Posts: 291
Joined: Monday 19 January 2015 10:14
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Enable/disable timer from events / LUA script

Post by Eduard » Monday 18 January 2016 19:35

Here is a simple python example

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&param=enabletimer&idx=1"

DomoticzRequest(url)
Hope it get's you started!
3x Raspberry Pi (Master, Slave & Test)
1x Test VM Windows (VS 2015)
1x Test VM Ubuntu

User avatar
G3rard
Posts: 827
Joined: Wednesday 04 March 2015 23:15
Target OS: Linux
Domoticz version: V3.8153
Location: The Netherlands
Contact:

Re: Enable/disable timer from events / LUA script

Post by G3rard » Sunday 24 January 2016 18:45

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.
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.
Ubuntu Server 14.04 | Domoticz v3.8153 | RFXtrx433E | Z-Wave Aeotec Z-Stick S2
Frontpage | Sonos PHP | Dark th3me | Sony Bravia Python plugin | Sonos Python plugin

clkoolen
Posts: 6
Joined: Sunday 17 January 2016 20:45
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Enable/disable timer from events / LUA script

Post by clkoolen » Sunday 31 January 2016 16:26

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.

clkoolen
Posts: 6
Joined: Sunday 17 January 2016 20:45
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Enable/disable timer from events / LUA script

Post by clkoolen » Saturday 06 February 2016 21:24

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.

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&param=disabletimer&idx="
else:
  json_command = "/json.htm?type=command&param=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)


Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests