Script examples (Lua)

Must be cleaned all topics go to the right subforum
User avatar
mbliek
Posts: 800
Joined: Friday 12 July 2013 14:08
Target OS: Raspberry Pi
Domoticz version: beta
Location: the Netherlands
Contact:

Re: Script examples (Lua)

Postby mbliek » Thursday 19 September 2013 19:30

Than you need to change 8080 to 80
Op zoek naar een Domoticz Start Set?


Like ons op Facebook en krijg een cadeaubon van €5,00

simon_rb
Posts: 614
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Script examples (Lua)

Postby simon_rb » Friday 20 September 2013 0:00

Hi, great scripts!!

I am looking to open and close my curtains at sunrise and sunset. I have an iTach flex to do this as the curtains are infrared. I have been given a script which is python based to send the required codes to the flex.

Can I get Domoticz to run this script at sunrise, and a different one at sunset (one with close commands and one with one commands. The script is below:-

#!/usr/bin/python
import socket
HOST2 = '<addressOfGCUnit>'
PORT2 = <portOfGCUnit>
s = socket.socket( socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST2, PORT2))
s.sendall("<commandCode>\r")
response = s.recv(24) #This is the echo back from iTach
print "Response from send(<whateverStringYouWantToGetBack-OPTIONAL>):", response

Cheers people :-)

User avatar
Dynamic
Posts: 179
Joined: Friday 12 July 2013 14:50
Target OS: -
Domoticz version:
Location: Enschede
Contact:

Re: Script examples (Lua)

Postby Dynamic » Friday 20 September 2013 8:01

mbliek wrote:Than you need to change 8080 to 80


I did that already ;-)
As workaround I renamed my iPhone, so it doesn't have a name with spaces in it. The script is working now!

Now i'm struggling to create a cronjob. I did cron -e and added this line:

Code: Select all

1 * * * * /ipresence/bluepresence.sh


I created a folder 'ipresence' with the script in it. But is doesn't run. I think there is something wrong with the path I specified.

User avatar
mbliek
Posts: 800
Joined: Friday 12 July 2013 14:08
Target OS: Raspberry Pi
Domoticz version: beta
Location: the Netherlands
Contact:

Postby mbliek » Friday 20 September 2013 8:19

To run it every min. you need this: */1 * * * *
And did you made that map in the domoticz scripts folder? Than you need this path:

home/pi/domoticz/scripts/ipresence/blueprsence.sh
Op zoek naar een Domoticz Start Set?


Like ons op Facebook en krijg een cadeaubon van €5,00

User avatar
Keptenkurk
Posts: 437
Joined: Wednesday 21 August 2013 17:24
Target OS: -
Domoticz version:
Location: Waalre, The Netherlands
Contact:

Re: Script examples (Lua)

Postby Keptenkurk » Friday 20 September 2013 13:10

@simon
The way of IP communication in the python example is pretty low level and i wouldn't know how to integrate that (not saying that it cannot be done).
I'm not familiar with the iTach products (or your specific model) but i got this http API description from their site (scroll down to IR command transmission and IR Learning).
If you can use these to talk to your iTach device from your browser then scripting this is no issue.

simon_rb
Posts: 614
Joined: Wednesday 07 August 2013 19:09
Target OS: -
Domoticz version:
Location: UK
Contact:

Re: Script examples (Lua)

Postby simon_rb » Friday 20 September 2013 14:21

Keptenkurk

Thank you for your reply. I have never script before. I'm currently waiting for a replacement flex, once I have it back up and running I'll attempt to write a new script.

Thanks again.

:-)

User avatar
Keptenkurk
Posts: 437
Joined: Wednesday 21 August 2013 17:24
Target OS: -
Domoticz version:
Location: Waalre, The Netherlands
Contact:

Re: Script examples (Lua)

Postby Keptenkurk » Friday 20 September 2013 14:50

Neither did i before last month. But this forum and Google provide a lot! Take your time and have fun!

laggmunk
Posts: 44
Joined: Sunday 14 July 2013 16:49
Target OS: -
Domoticz version:
Contact:

Re: Script examples (Lua)

Postby laggmunk » Tuesday 24 September 2013 10:11

Prescence detection using two motion detectors:

This is a script I use to determine if anyone is still upstairs, it is a time based script that runs every minute and it uses two motion detectors to determine if there is any movement upstairs, and which direction (up or down) the last person was heading, if there is no motion upstairs, and the last person was heading downstairs it turns off all lights in the group "scene:lights_upstairs" when 30 minutes have passed.

One motion sensor is located on the top floor, and the other one in the staircase and the timedifference between their lastupdated timestamps determines direction.

there is also a manual switch downstairs that turns on the ceiling light on the top floor, and to allow time for someone to make it up the stairs I never turm off the lights if the ceiling light was switched on witin the last two minutes (120s), if you turn on the ceiling light upstairs, but never go up, it will automatically turn off the next time the script runs after two minutes.

Code: Select all

function timedifference (s)
   year = string.sub(s, 1, 4)
   month = string.sub(s, 6, 7)
   day = string.sub(s, 9, 10)
   hour = string.sub(s, 12, 13)
   minutes = string.sub(s, 15, 16)
   seconds = string.sub(s, 18, 19)
   t1 = os.time()
   t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
   difference = os.difftime (t1, t2)
   return difference
end

commandArray = {}
print('evaluating if someone is upstairs')

if (otherdevices['topfloor_motion'] == 'Off') and (timedifference(otherdevices_lastupdate['topfloor_ceiling_lamp']) > 120) then
   if (timedifference(otherdevices_lastupdate[topfloor_motion']) > 1800) then
      if timedifference(otherdevices_lastupdate['top_stairs_motion']) < timedifference(otherdevices_lastupdate['topfloor_motion']) then
         commandArray['Scene:topfloor_lights']='Off'
         print('turning off, no movement upstairs for more than 30m')
      end
   end
end



this script can sometimes be annoying, if I am in my reading chair upstairs without moving for more than 30minutes, and my wife goes downstairs all lights will be turned off.
I therefore have another script that checks if there is motion upstairs and if the lights where switched within the last 30s, and then turns them on again, that way I don't have to get up, I just wave my hand and the lights come back on.

alfred_j_kwak
Posts: 253
Joined: Friday 20 September 2013 18:49
Target OS: Raspberry Pi
Domoticz version: 2.3530
Location: Finland
Contact:

Re: Script examples (Lua)

Postby alfred_j_kwak » Thursday 10 October 2013 20:59

This is maybe more like bash related thing, but I wrote script to check once in a minute if my phone is in range of domoticz server bluetooth. Now I get event once in a minut. I liked to get event only when state changes. Do I have to write current status into file and read it back from file before checking my bluetooth so I could send JSON only when status is different than previous?

Sorry about bad english. :oops:

-Jussi-

l0gic
Posts: 134
Joined: Tuesday 08 October 2013 9:35
Target OS: Raspberry Pi
Domoticz version: Latest
Contact:

Re: Script examples (Lua)

Postby l0gic » Wednesday 16 October 2013 17:55

Hi Jussi,
I don't know what phone you have but I use an Android phone and run the app called "AutomateIT"
This app runs tasks when certain criteria are met.
I set one up such that when I log on to my home wi-fi connect to a web site.
The web site I connect to is my local Domoticz server with a json command string to operate a dummy switch.
e.g.
http://192.168.2.100:8080/json.htm?type=command&param=switchlight&idx=17&switchcmd=On&level=0
You can then wrap some logic around the switch to do what functions you require.

You can easily find the switch number by running this json command
http://192.168.2.100:8080/json.htm?type=command&param=getlightswitches

HTH


Kevin
Non credus crepitus

l0gic
Posts: 134
Joined: Tuesday 08 October 2013 9:35
Target OS: Raspberry Pi
Domoticz version: Latest
Contact:

Re: Script examples (Lua)

Postby l0gic » Monday 21 October 2013 10:47

Hi
this is a script I've written to gradually turn off the lights at bedtime;

it relies on a dummy switch called Bedtime which is operated when it is time to go to bed.
It scrolls around to check of the Bedtime switch is on and if it is it will then keep checking for any lights left on, the time since the Bedtime switch was operated and then power off the lights at set intervals.

Code: Select all

t1 = os.time()

s = otherdevices_lastupdate['Bedtime']

-- returns a date time like 2013-07-11 17:23:12


year = string.sub(s, 1, 4)

month = string.sub(s, 6, 7)

day = string.sub(s, 9, 10)

hour = string.sub(s, 12, 13)

minutes = string.sub(s, 15, 16)

seconds = string.sub(s, 18, 19)





commandArray = {}


-- *** Get the difference between last Bedtime switch operate time  and now
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}

difference = (os.difftime (t1, t2))


-- *** Check to see if Bedtime switch is on
if (otherdevices['Bedtime'] == 'On') then
    td = "Time Difference = " .. difference
    print (td)
    print ("Device - Bedtime Switch is On")

   -- *** Check to see if all lights are off, if so reset the Bedtime switch
   if (otherdevices['Kevin Lamp'] == 'Off') and (otherdevices['Sharon Lamp'] == 'Off') and (otherdevices['Kitchen Main'] == 'Off') and (otherdevices['Kitchen Kettle'] == 'Off') and (otherdevices['Conservatory Lamp'] == 'Off') and (otherdevices['Outside Lights'] == 'Off') then
   print ("All the lamps are Off")
   commandArray['Bedtime']='Off'
        commandArray['SendNotification']='Bedtime Alert#All lights Off -  Resetting Bedtime switch'
   end

    -- *** Turn off Front Room lights after 60 seconds [1 min] (check duration to 180 seconds [3 min])
   if difference > 60 and difference < 180 then
       commandArray['Kevin Lamp']='Off'
       commandArray['Sharon Lamp']='Off'
       print ("Front room lights Off - 1 minute after activation")
   end

   -- *** Turn off Conservatory light and Kitchen Main after 300 seconds [5 min] (check duration to 420 seconds [7 min])
   if difference > 300 and difference < 420 then
      commandArray['Conservatory Lamp']='Off'
      commandArray['Kitchen Main']='Off'
      print ("Conservatory and Kitchen Main lights Off - 5 minutes after activation")
   end

   -- *** Turn off Kitchen Kettle lights after 600 seconds [10 min] (check duration to 720 seconds [12 min])
   if difference > 600 and difference < 720 then
      commandArray['Kitchen Kettle']='Off'
      print ("Kitchen Kettle light Off - 10 minutes after activation")
   end

   -- *** Turn off Outside lights after 10800 seconds [3 hrs] (check duration to 10920 seconds [3 hrs 2 min])
   if difference > 10800 and difference < 10920 then   
      commandArray['Outside Lights']='Off'
      print ("Outside lights Off - 3 hours after activation")
   end

end


return commandArray


There are a number of print commands that I have left in as they are useful for debugging while setting the script up.
I also have a final email once all lights are off for the night, this can also be removed.

I have set up a link on my iPad home screen that sends a json command to turn on the Bedtime switch, other methods are available :)

Hope this helps someone.

Kevin
Non credus crepitus

maxtrash
Posts: 165
Joined: Tuesday 06 August 2013 1:31
Target OS: -
Domoticz version:
Contact:

Re: Script examples (Lua)

Postby maxtrash » Wednesday 23 October 2013 22:18

I'm trying to update a gas (m3) style meter from a lua-script.

this however, doesn't work:
commandArray['OpenURL']="192.168.1.24:8080/json.htm?type=command&param=udevice&hid=3&did=gas2&dunit=1&dsubtype=0&dtype=113&nvalue=0&svalue=500"

but if I execute the url separately from the browser it's fine. What is wrong or are there more elegant ways to do this (kinda strange using json from within domoticz)

User avatar
gizmocuz
Posts: 7939
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi
Domoticz version: beta
Location: Top of the world
Contact:

Re: Script examples (Lua)

Postby gizmocuz » Friday 25 October 2013 7:34

@maxtrash,

There are probably two problems with that last OpenURL call:

1. The IP address should be: 127.0.0.1:8080 if you want to update a value on that machine, if you send it to another domoticz, then please check your IP/Port, because i verified this, and this is working and not blocking
2. I do not know why you use all parameters but if your Gas device has index (idx) 10 for example (this is shown in the devices tab) you could do:

commandArray['OpenURL']="127.0.0.1:8080/json.htm?type=command&param=udevice&idx=10&nvalue=0&svalue=12.3;45;2"
(^Please not this nValue/sValue is for a Temp+Hum sensor, you need to change this)

New in version #1113
Instead of using OpenURL you can now issue:
commandArray['UpdateDevice']='10|0|23.4;44;3'
(It is separated by a Pipe, [idx][nvalue][svalue])

Hope this solves your problem!

With kind regards,
Rob
Quality outlives Quantity!

maxtrash
Posts: 165
Joined: Tuesday 06 August 2013 1:31
Target OS: -
Domoticz version:
Contact:

Re: Script examples (Lua)

Postby maxtrash » Friday 25 October 2013 16:55

Now we're talking! Great, I'll try it tonight using update device.

You're right about 127.0.0.1 probably, didn't think of it. However not relevant anymore I guess :-)

maxtrash
Posts: 165
Joined: Tuesday 06 August 2013 1:31
Target OS: -
Domoticz version:
Contact:

Re: Script examples (Lua)

Postby maxtrash » Friday 25 October 2013 19:18

something strange is happening.

I found out my original try didn't work because I was using " instead of '
:oops:

out of these options everything works, except the new UpdateDevice though ?

Code: Select all

if ((devicechanged['Elektriciteit'])) then
   print ("Devicechanged elektriciteit")
   print (otherdevices_svalues['Graaddagen'])
   print (otherdevices_svalues['Gas'])
   
   --commandArray['OpenURL']='192.168.1.24:8080/json.htm?type=command&param=udevice&hid=3&did=gas2&dunit=1&dsubtype=0&dtype=113&nvalue=0&svalue=501'
   commandArray['OpenURL']='192.168.1.24:8080/json.htm?type=command&param=udevice&idx=64&nvalue=0&svalue=502'
   --commandArray['OpenURL']='127.0.0.1:8080/json.htm?type=command&param=udevice&idx=64&nvalue=0&svalue=503'
   --commandArray['UpdateDevice']='64|0|504'

end


update: OpenUrl works fine, except I can only send one URL in the script. If I put in two it will only execute the last one.

User avatar
Keptenkurk
Posts: 437
Joined: Wednesday 21 August 2013 17:24
Target OS: -
Domoticz version:
Location: Waalre, The Netherlands
Contact:

Re: Script examples (Lua)

Postby Keptenkurk » Friday 01 November 2013 20:33

I want to share this script example. Not because it is really useful to many (and not to show that i know programming because i don't) but is contains some Lua things which might serve as an example in other scripts. At least i had fun in googeling it together and make it work.
Goal: I wanted to graph the value of the sun's x-ray activity in Domoticz. To have it on my dashboard knowing what has been going on the past 24h. I do this by reading a web page containing this value every minute, extracting the data and posting it into a Domoticz dummy temperature sensor.

Code: Select all

-------------------------------------------------------------------------------
--- Lua Time script  v1.0
--- Runs every minute
---
--- Purpose:
--- Reads solar xray flux value from website and graphs it in temperature graph
--- Background: http://en.wikipedia.org/wiki/Solar_flare
-------------------------------------------------------------------------------

--- returns num rounded up to idp decimals
function round(num, idp)
  local mult = 10^(idp or 0)
  return math.floor(num * mult + 0.5) / mult
end

commandArray = {}

--- To have a 1MB /var/tmp directory in RAM add the line
---    tmpfs /var/tmp tmpfs nodev,nosuid,size=1M 0 0
--- to the /etc/fstab file
---
--- Read Solar data from http://sol24.net/m/ into xray_data_string
tmp_filename = '/var'..os.tmpname()
os.execute('curl "http://sol24.net/m/" > '..tmp_filename)
infile = io.open(tmp_filename,'r')
xray_data_str=infile:read('*all')

--and clean up temp file
infile:close()
os.remove( tmp_filename )

-- Process xray_data_string to retrieve current x-ray value near label "flux:" which looks like C3.7
xray_pos = string.find(xray_data_str, "X-ray flux:")
xray_power10 = string.sub(xray_data_str,xray_pos+88, xray_pos+88)
xray_value= string.sub(xray_data_str,xray_pos+89, xray_pos+91)
if      xray_power10 == 'B' then xray_value_powered = xray_value * 10
elseif  xray_power10 == 'C' then xray_value_powered = xray_value * 100
elseif  xray_power10 == 'M' then xray_value_powered = xray_value * 1000
elseif  xray_power10 == 'X' then xray_value_powered = xray_value * 10000
elseif  xray_power10 == 'Y' then xray_value_powered = xray_value * 100000
end

--transform this value to be presented on a logaritmic 0~50 scale
xray_index = 10*round(math.log(xray_value_powered,10),2)

--show what we are doing in the log
print(string.format("Current GOES Xray flux is %s%s indexed to %s.",xray_power10,xray_value,xray_index))

--and put the value in the graph
commandArray['UpdateDevice']='66|0|'..xray_index

--done
return commandArray

and it works:
GOES flux NOAA.JPG
GOES flux NOAA.JPG (74.9 KiB) Viewed 4096 times

GOES flux domoticz.JPG
GOES flux domoticz.JPG (53.58 KiB) Viewed 4096 times

l0gic
Posts: 134
Joined: Tuesday 08 October 2013 9:35
Target OS: Raspberry Pi
Domoticz version: Latest
Contact:

Double Click

Postby l0gic » Saturday 02 November 2013 23:59

Hi guys,
after seeing a discussion on another thread about controlling two separate lights using one switch unit I thought I'd give it a go.
I don't particularly need it but I guess it could be useful.
The code is not elegant but sort of works. :D

The switch, Spare Byron Switch (B1), operates Ceiling Unit 15 (H15) on a single click i.e. normal conditions but also operates Ceiling Unit 16 (H16) using double click.
A double click is defined as two events within 5 seconds.

A file (SwitchB1Time.txt) is expected to exist in the Domoticz directory (not in the Domoticz\scripts or Domoticz\scripts\lua directories) and have data in 3 lines which is read and modified.
Line 1 holds the last switch On time
Line 2 holds the last switch Off time
Line 3 holds the last state of Ceiling Unit 15 (H15)

To seed the file enter;
12345
12346
Off

or similar. Real data will replace these once the code has run.

Note - this code is not perfect, if double clicking the single click unit will operate for the duration of the double click before being switched back to it's original state.
I may revisit this in a few days if I have some time.

Code: Select all


commandArray = {}


-- ***** Switch On Section *****

if (devicechanged['Spare Byron Switch (B1)'] == 'On') then

   tNew = os.time()

-- Get current state of single click light
   if (otherdevices['Ceiling Unit 15 (H15)'] == 'Off') then
     singleclicklamp = "Off"
   else
     singleclicklamp = "On"   
   end
   

-- Get last time switch was operated
   local file = io.open("SwitchB1Time.txt", "r")
   TimeOnOld = file:read()
   TimeOffOld = file:read()
   LightStateOld = file:read()
   file:close()

-- Compare this on time with last on time and get the difference
   On_Difference = tNew - TimeOnOld
   Off_Difference = tNew - TimeOffOld
   DoubleClick = "Null"


   pton = "Time difference in seconds since last On operation = " .. On_Difference
   print(pton)
   ptoff = "Time difference in seconds since last Off operation = " .. Off_Difference
   print(ptoff)
   
-- Check for Double Click
   if (On_Difference < 5) then -- switched on twice within 5 seconds
     DoubleClick = "True"
   else 
     DoubleClick = "False"
   end

   pdc = "Double click event = " .. DoubleClick
   print(pdc)

   if (DoubleClick == "False") then
     commandArray['Ceiling Unit 15 (H15)']='On'
   end

   if (DoubleClick == "True") then
     commandArray['Ceiling Unit 16 (H16)']='On'
     if (LightStateOld == "Off") then
       commandArray['Ceiling Unit 15 (H15)']='Off'
     end
   end

   -- save new time to file

   local file = io.open("SwitchB1Time.txt", "w")
   file:write(tNew)
   file:write("\n")
   file:write (TimeOffOld)
   file:write("\n")
   file:write(singleclicklamp)
   file:close()
   print ("File SwitchB1Time.txt written")

end

-- ***** Switch Off Section *****

if (devicechanged['Spare Byron Switch (B1)'] == 'Off') then

   tNew = os.time()

-- Get current state of single click light
   if (otherdevices['Ceiling Unit 15 (H15)'] == 'Off') then
     singleclicklamp = "Off"
   else
     singleclicklamp = "On"   
   end
   

-- Get last time switch was operated
   local file = io.open("SwitchB1Time.txt", "r")
   TimeOnOld = file:read()
   TimeOffOld = file:read()
   LightStateOld = file:read()
   file:close()

-- Compare this on time with last on time and get the difference
   On_Difference = tNew - TimeOnOld
   Off_Difference = tNew - TimeOffOld
   DoubleClick = "Null"


   pton = "Time difference in seconds since last On operation = " .. On_Difference
   print(pton)
   ptoff = "Time difference in seconds since last Off operation = " .. Off_Difference
   print(ptoff)
   
-- Check for Double Click
   if (Off_Difference < 5) then -- switched on twice within 5 seconds
     DoubleClick = "True"
   else 
     DoubleClick = "False"
   end

   pdc = "Double click event = " .. DoubleClick
   print(pdc)

   if (DoubleClick == "False") then
     commandArray['Ceiling Unit 15 (H15)']='Off'
   end

   if (DoubleClick == "True") then
     commandArray['Ceiling Unit 16 (H16)']='Off'
     if (LightStateOld == "On") then
       commandArray['Ceiling Unit 15 (H15)']='On'
     end
   end

   -- save new time to file

   local file = io.open("SwitchB1Time.txt", "w")
   file:write(TimeOnOld)
   file:write("\n")
   file:write (tNew)
   file:write("\n")
   file:write(singleclicklamp)
   file:close()
   print ("File SwitchB1Time.txt written")

end



return commandArray


Hope this helps someone.

Kevin
Non credus crepitus

l0gic
Posts: 134
Joined: Tuesday 08 October 2013 9:35
Target OS: Raspberry Pi
Domoticz version: Latest
Contact:

Script examples (Lua) - Getting date time variables

Postby l0gic » Monday 09 December 2013 12:33

Hi,
I needed to pull some real time date and time variables while scripting so I knocked up a test script to investigate what is available.
In case anyone else needs to get the same type of info here is the script;

Code: Select all

-- Script to print out the various time and date variables available in Domoticz for reference
-- Output is in the log file [Setup -> Log from the menu]
-- also loads the values into variables for use elsewhere in the script if needed
-- If using this script delete the lines that you do not need to save resources
-- Not all variables have been presented but the full available list is below;

-- Variable details (from http://www.lua.org/pil/22.1.html)
-- %a   abbreviated weekday name (e.g., Wed)
-- %A   full weekday name (e.g., Wednesday)
-- %b   abbreviated month name (e.g., Sep)
-- %B   full month name (e.g., September)
-- %c   date and time (e.g., 09/16/98 23:48:10)
-- %d   day of the month  [01-31]
-- %H   hour, using a 24-hour clock  [00-23]
-- %I   hour, using a 12-hour clock  [01-12]
-- %M   minute  [00-59]
-- %m   month  [01-12]
-- %p   either "am" or "pm"
-- %S   second  [00-61]
-- %w   weekday  [0-6 = Sunday-Saturday]
-- %x   date (e.g., 09/16/98)
-- %X   time (e.g., 23:48:10)
-- %Y   full year (1998)
-- %y   two-digit year  [00-99]
-- %%   the character `%´


print(" ")
print ("*******************")
print(" ")
-- Year
 nowyear = os.date("%Y")
 print(os.date("Current Year - %Y"))
-- Month
nowmonth = os.date("%m")
 print(os.date("Current Month - %m and %b and %B"))
--Day
nowday = os.date("%d")
nowdow = os.date("%a") -- day of week truncated (%A full)
 print(os.date("Current day - %d and %a and %A"))
-- Hour
nowhour = os.date("%H")
 print(os.date("Current hour (24h) - %H and (12h) - %I"))
-- Minute
nowminute = os.date("%M")
 print(os.date("Current minute - %M"))
-- Second
nowsecond = os.date("%S")
 print(os.date("Current second - %S"))
-- Full Date
 nowdate = os.date("%x")
 print(os.date("Current full date - %x"))
 -- Full Time
  nowtime = os.date("%X")
 print(os.date("Current full time - %X"))
 -- Full Date and Time
nowdatetime = os.date("%c")
 print(os.date("Current full date and time - %c"))

print(" ")
print ("*******************")
print(" ")

commandArray = {}
-- nothing to see here
return commandArray


Hope this helps someone.

cheers

Kevin
Non credus crepitus

Ode-B
Posts: 34
Joined: Monday 09 December 2013 14:23
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Script examples (Lua)

Postby Ode-B » Tuesday 10 December 2013 8:54

alfred_j_kwak wrote:This is maybe more like bash related thing, but I wrote script to check once in a minute if my phone is in range of domoticz server bluetooth. Now I get event once in a minut. I liked to get event only when state changes. Do I have to write current status into file and read it back from file before checking my bluetooth so I could send JSON only when status is different than previous?

Sorry about bad english. :oops:

-Jussi-


Hi,

Did you solve this? Trying to do the same thing.

-Ode

alfred_j_kwak
Posts: 253
Joined: Friday 20 September 2013 18:49
Target OS: Raspberry Pi
Domoticz version: 2.3530
Location: Finland
Contact:

Re: Script examples (Lua)

Postby alfred_j_kwak » Tuesday 10 December 2013 9:53

No - I give up. :)
I still get events once in minute. With android phone you could use Tasker to send JSON, but still there could be 'misfires'. Tasker is able to trigger both ways. First when you enter into radius and another time when you left area.

-Jussi-


Return to “Scripts [cleaning in progress]”

Who is online

Users browsing this forum: No registered users and 2 guests