Script examples (Lua)

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

Re: Script examples (Lua)

Post by laggmunk » Friday 02 August 2013 13:04

if you mean the simple os.execute example, then you're welcome, if not please paste a link as I can't find any other example.

you can also extend the capability of interacting with external hw/sw by using rfid tags.

I use tasker URL launcher on my phone, and by programming a domoticz json URL into the tag using a tag writer I can have domoticz perform action both in domoticz and on the OS level whenever I touch my tag to the phone

that way I can wake up my media center and fileserver, disarm my CCTV system and turn on appropriate lights when coming home.

User avatar
CopyCatz
Developer
Posts: 751
Joined: Thursday 11 July 2013 17:28
Target OS: -
Domoticz version:
Location: Outer Heaven
Contact:

Re: Script examples (Lua)

Post by CopyCatz » Friday 02 August 2013 14:26

I noticed you simply set the waked device back to off so you can press it again. I'm thinking of a ping script (time) that would check if the device is still up. But ping would probably also go via os command, don't know how to catch the status from the ping response..

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

Re: Script examples (Lua)

Post by laggmunk » Friday 02 August 2013 15:32

two ways of catching the exit status or output I found was to either use the call io.popen something like this:

Code: Select all

 f = assert (io.popen ("ls -l"))
  
 for line in f:lines() do
   print(line)
 end -- for loop
   
 f:close()
or using temporary files:

Code: Select all

-- get a temporary file name
n = os.tmpname ()

-- execute a command
os.execute ("ls -l > " .. n)

-- display output
for line in io.lines (n) do
  print (line)
end

-- remove temporary file
os.remove (n)
I haven't tried either of the methods yet though.

simonrg
Posts: 1055
Joined: Tuesday 16 July 2013 22:54
Target OS: Raspberry Pi
Domoticz version:
Location: North East England
Contact:

Re: Script examples (Lua)

Post by simonrg » Thursday 08 August 2013 0:18

Electricity Monitoring Script

My Owl energy monitor independently monitors the normal household electrical use, the heat pump and the solar generation.

This script signals when more current is being generated by the solar panels than is being used by the house and the heat pump, it currently turns the hall light on when more solar electricity is being generated and turns it off when less solar electricity is being generated. The idea was to replace this with a red and a green light. More usefully it records when this happens in the log, so I am able to monitor the import and the export of electricity.

I was unable to find the current values being returned in 'devicechanged', so got them from otherdevices_svalues['Owl'], then extracted each one form the single string by finding the ;s which seperate the values. Is there an easier way to do this?

In Domoticz I have created a dummy switch called 'Free' to record the current state, so if more solar is being generated then this is 'On' and if less then this is 'Off', this is purely a way of keeping the current state and allowing the script to only log when the state changes. Obviously I could have just stuck to the real light, but I suspect I will get fed up with this very quickly and purely keep the logging, this seemed simpler than creating a file to check for or to store a value in. However, is there a better way to keep the state between calls of the script?

I have left in the debugging code but commented it out.

Code: Select all

commandArray = {}

if (devicechanged['Owl']) then
        owl = otherdevices_svalues['Owl']
--        print(owl)
        owlsc = string.find(owl,';')
        house = tonumber(string.sub(owl, 1, owlsc-1))
        owl = string.sub(owl, owlsc+1)
        owlsc = string.find(owl,';')
        heatpump = tonumber(string.sub(owl, 1, owlsc-1))
        solar = tonumber(string.sub(owl, owlsc+1))
--        local file = io.open("example.txt", "a")
--        for i, v in pairs(devicechanged) do file:write(i, '   ', v, '\n') end
--        file:write('House  ', tostring(house), 'A\n')
--        file:write('HeatPump  ', tostring(heatpump), 'A\n')
--        file:write('Solar  ', tostring(solar), 'A\n')
--        file:close()
--        print(house, heatpump, solar)
        if (solar > (house + heatpump) and otherdevices['Free'] == 'Off') then
-- Change of state - more solar generated than being used so write in log, change status
--  and turn on hall light
                 print('Energy Free\n')
                 commandArray['Free'] = 'On'
                 commandArray['Hall'] = 'On'
        elseif (solar < (house + heatpump) and otherdevices['Free'] == 'On') then
-- Change of state - now less solar generated than being used so write in log, change status
--  and turn off hall light
                 print('Energy Costs\n')
                 commandArray['Free'] = 'Off'
                 commandArray['Hall'] = 'Off'
        end
end
return commandArray
Raspberry Pi 2 B - [email protected] PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266

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

Re: Script examples (Lua)

Post by Dynamic » Thursday 08 August 2013 10:45

CopyCatz wrote:Made a time script that determines whether the living room is empty, if there's no movement for an hour switch on dummy device "Huiskamer leeg" (livingroom empty).

Code: Select all

code
After which I can run other stuff based on the fact that the room is empty.
Nice script! Implemented it, but was not able to test it. Need to buy new batteries for my kaku-motionsensor (how long did the batteries last in your system?)

nvnoort
Posts: 3
Joined: Friday 26 July 2013 9:36
Target OS: -
Domoticz version:
Contact:

Re: Script examples (Lua)

Post by nvnoort » Saturday 10 August 2013 15:07

After some puzzeling I found a way to make domoticz work as an alarm system. Basically I wanted to use scenes to set an alarm state, but since there is not that much control over scenes I have created a fake light switch with a remote that sets a light to a certain state. Offcourse I also want to have a way to set the alarm, but have time to leave the house before it actually primes the alarm. When I do this I also want to be able to see it is doing this so signal with the lights.

The problem I found is that offcourse only at the end of the script it sets the state of the lights, so flashing the lights would have to be done by going through the script multiple times. To have states available in multiple stages of the script I am now using files that are created and filled with parameters.

The script looks like this:

Code: Select all

commandArray = {}
nietklaar = 0
filenaam = "/volume1/Extensions/domoticz/alarmaanzetten"

-- check if the sensors are closed
if (devicechanged['Alarm_uitgang'] == 'On' and otherdevices['Raamsensor achterraam'] == 'Open') then
	nietklaar = 1
	print('Achterraam sensor niet klaar')
end

if (devicechanged['Alarm_uitgang'] == 'On' and otherdevices['Deursensor achterdeur'] == 'Open') then
	nietklaar = 1
	print('Achterdeur sensor niet klaar')
end

if (devicechanged['Alarm_uitgang'] == 'On' and otherdevices['Raamsensor Voorraam'] == 'Open') then
	nietklaar = 1
	print('Voorraam sensor niet klaar')
end

if (devicechanged['Alarm_uitgang'] == 'On' and otherdevices['Deursensor Voordeur'] == 'Open') then
	nietklaar = 1
	print('Voordeur sensor niet klaar')
end

-- prime the parameters for the file for alarm_uitgang
if (devicechanged['Alarm_uitgang'] == 'On' and otherdevices['Alarm'] == 'Off' and nietklaar == 0) then
   if otherdevices['Woonkamerlicht'] == 'On' then
      ama = 5
   else 
      ama = 4
   end
   am = 0
   --ama = 0
   local f = assert(io.open(filenaam, "w"))
   f:write(am, "\n")
   f:write(ama, "\n")
   f:close()
end

--always done when alarm_uitgang is set, also the first time after priming the parameters
if (otherdevices['Alarm_uitgang'] == 'On' and otherdevices['Alarm'] == 'Off' and nietklaar == 0) then
   local f = assert(io.open(filenaam, "r"))
   local teller = tonumber(f:read("*line"))
--   print(teller)
   local totaalaantal = tonumber(f:read("*line"))
--   print(totaalaantal)
   f:close()
   alarmdeel = math.fmod(teller,2)
   alarm = 1

--   print('in alarm subgedeelte')

   if (teller < totaalaantal and alarmdeel == 1) then 
      commandArray['Woonkamerlicht']='Off'
--      print('Licht uitzetten')
   end

   if (teller < totaalaantal and alarmdeel == 0) then 
      commandArray['Woonkamerlicht']='On'
--      print('Licht aanzetten')
   end

-- only after about a minute the alarm is really primed, this depends on the speed at which events happen that trigger the script
   if (teller == 10) then 
      commandArray['Alarm']='On'
      commandArray['SendNotification']='Alarm#Alarm Aanzetten'
--      for i, v in pairs(otherdevices) do print(i, v) end 
      commandArray['Alarm_uitgang']='Off'
--      print('Alarm aanzetten')
      commandArray['Woonkamerlicht']='Off'
   end

  -- loop to make sure the light is off and on for a short time
   local clock=os.clock
   local t1 = clock()
   local t2 = clock()
   repeat
       t2=clock()
   until t2-t1>1
   
-- set the new parameters for the file and write them to the file
   am = teller +1
   ama = totaalaantal
   local f = assert(io.open(filenaam, "w"))
   f:write(am, "\n")
   f:write(ama, "\n")
   f:close()

end


-- if anything is not set correctly, door is open or the alarm  is already turned on, the process is aborted
if (devicechanged['Alarm_uitgang'] == 'On' and (otherdevices['Alarm'] == 'On' or nietklaar == 1)) then
   commandArray['Alarm_uitgang']='Off'
   commandArray['SendNotification']='Alarm#Alarm aanzetten niet gelukt'
end


--print('Alarm aanzetten Eind')
return commandArray
Offcourse, during the 2 times flashing of the light the script is called again by turning on and off the light. After that the triggering of the script depends on the speed at which events occur that trigger the script. I do have 4 temperature devices in domoticz that sent info regurarly. an advantage of doing it like this is that it leaves plenty of time to press the off-button on the alarm_uitgang again which will make the process stop. I should put some light flashing in that too maybe to acknowledge this state.

I have also been thinking about an hearable way to acknowledge setting on and off the alarm, but have not found anything that can beep yet. any ideas on this would be welcome.

If you have any ideas/remarks let me know. I am also working on a script that is triggered when the alarm is triggered, but have problems having the lights flashing in a consistant way.

Niels van Noort

reteip
Posts: 4
Joined: Tuesday 23 July 2013 14:57
Target OS: -
Domoticz version:
Contact:

Re: Script examples (Lua)

Post by reteip » Tuesday 20 August 2013 11:57

I'm busy with a simple bluetooth monitor. The idea is eventually to add some extra logic and control to the security system. When the phone is in the house, the system should not be armed. Mainly it just detects if a user is away or not by checking the Mac address. I change the state of a dummy device type sensor that is On or Off when the user is at home or away.

My Lua script till now :

Code: Select all

-- Security check with bluetooth devices
commandArray = {}
dummydevice='At Home'
filename = string.gsub("/tmp/[email protected]@@", "@@@", tostring(math.random(10000000,99999999)))
os.execute("/home/pi/domoticz/scripts/bluetooth/issecure.sh > " .. filename)

local file=io.open(filename,"r")
sContents=file:read()
file:close()
os.remove(filename)

if(string.match(sContents,'[1-9]')) then
        print ("Everything secure")
        if (otherdevices[dummydevice] == 'Off') then
                commandArray[dummydevice] = 'On'
        end
else
        print ("Not secure")
         if (otherdevices[dummydevice] == 'On') then
                commandArray[dummydevice] = 'Off'
        end
end

return commandArray
This script runs issecure.sh. That script contains :

Code: Select all

#/bin/bash
secureitems=0
total=0
while read macaddress; do
        total=$(($total+1))
        NEXTNAME=$(hcitool name ${macaddress} 2>&1)
        if [ -n "$NEXTNAME" ]; then
                secureitems=$(($secureitems+1))
        fi

done  < /home/pi/domoticz/scripts/bluetooth/devices
echo $secureitems
if [ "$secureitems" -eq 0 ]; then
        exit 1
fi
I use Hcitool with the 'Name' function to check if the mac address i wrote in the /home/pi/domoticz/scripts/bluetooth/devices file responds. Name is the only function that i found that also works when my device (iPhone) has bluetooth simply on but is not paired to my raspberry. I don't want to pair it, i just want to see if it is around. With the name functions i only have to know the Mac address and add it to the devices file. Works with all my iDevices. Dunno if it works with other bluetooth devices like android phones etc. As far as my testing goes till now i didn't notice more battery drain then normal. Hcitool is part of the bluez library. Bluez can easily be installed on the raspberry.

I did ran in some issues with Lua. First my implementation checked the exit code of the shell script. If i read the manual of Lua the os.execute() function should give the return value. I really could not get this working properly. So i decided to use a temp file instead.

Next step : Couple this scripts to device changes. I've got a movement sensor in my living room, aswell a simple open/close detector on my front door. And of course i want to use the security panel functionality. If it works stable (no alarms when i'm at home ;)) i will couple it to the smoke alarm.

The bluetooth device i use is a cheap Conceptronic USB Adapter Bluetooth 200m Nano. The reach is about 20 meters inside my home. Since my Pi is in the living room it's large enough to use there as a security check.

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

Re: Script examples (Lua)

Post by mbliek » Monday 26 August 2013 17:20

I also made an Bluetooth "monitor". I bought an Trust bluetooth dongle for €10,-

I run my script thuis.sh with crontab every 30 sec.

This is my script thuis.sh, that's switching an dummy switch.
On when home and Off when not home.

Code: Select all

#!/bin/bash
 

# Domoticz server
SERVER="10.0.1.109:8080"
 
check=`hcitool name 7C:FA:DF:75:CC:4B`

echo $check
if expr "$check" '=' Menno
then
       echo "iPhone is binnen bereik"
       # Send data
	   curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=switchlight&idx=123&switchcmd=On"
else
       echo "iPhone is buiten bereik"
       # Send data
	   curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=switchlight&idx=123&switchcmd=Off"
fi
Two lua scrips.

script_device_alarm_thuis.lua

Code: Select all

commandArray = {}
if (devicechanged['Thuis'] == 'On' and otherdevices['Alarm'] == 'Arm Away') then
	commandArray['Alarm']='Off'
	commandArray['SendNotification']='#Welkom thuis, alarm uitgeschakeld'
	print('Alarm uitgeschakeld')
end

return commandArray
script_device_alarm_weg.lua

Code: Select all

commandArray = {}
if (devicechanged['Thuis'] == 'Off' and otherdevices['Alarm'] == 'Disarm') then
	commandArray['Alarm']='On'
	commandArray['SendNotification']='#Tot ziens, alarm ingeschakeld'
	print('Alarm ingeschakeld')
end

return commandArray

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

Re: Script examples (Lua)

Post by Dynamic » Friday 30 August 2013 14:01

mbliek wrote:I also made an Bluetooth "monitor". I bought an Trust bluetooth dongle for €10,-

I run my script thuis.sh with crontab every 30 sec.

This is my script thuis.sh, that's switching an dummy switch.
On when home and Off when not home.
Two lua scrips.

script_device_alarm_thuis.lua
script_device_alarm_weg.lua
What type did you use? And was it easy to install? I'm not a experienced linux-user, but this function looks really great!

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

Re: Script examples (Lua)

Post by mbliek » Friday 30 August 2013 14:10

Dynamic wrote:What type did you use? And was it easy to install? I'm not a experienced linux-user, but this function looks really great!
Well I was a Trust Bluetooth 3.0 USB adapter (10 meter range). But it was not very reliable. (maybe because it doesn't support HCI mode?)
So I bought a ICIDU 4.0 bluetooth dongle (http://www.replacedirect.nl/product/P01 ... 3godpWMAsA) It is much better (50 meter range) and supports HCI mode.

I'm not a experienced linux-user as well, I just copy and paste the code from internet :) and it worked.

If you need any help, just ask.

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

Re: Script examples (Lua)

Post by Dynamic » Friday 30 August 2013 14:12

mbliek wrote:
Dynamic wrote:What type did you use? And was it easy to install? I'm not a experienced linux-user, but this function looks really great!
Well I was a Trust Bluetooth 3.0 USB adapter (10 meter range). But it was not very reliable. (maybe because it doesn't support HCI mode?)
So I bought a ICIDU 4.0 bluetooth dongle (http://www.replacedirect.nl/product/P01 ... 3godpWMAsA) It is much better (50 meter range) and supports HCI mode.

I'm not a experienced linux-user as well, I just copy and paste the code from internet :) and it worked.

If you need any help, just ask.
Just 10 euro??? I'm gonna order it! Thnx for you help in advance!

reteip
Posts: 4
Joined: Tuesday 23 July 2013 14:57
Target OS: -
Domoticz version:
Contact:

Re: Script examples (Lua)

Post by reteip » Saturday 07 September 2013 11:10

I did some tests with my Conceptronic USB Adapter Bluetooth 200m Nano. The range works out to be pretty good. I now coupled it to check the bluetooth devices with my motion sensor and with my door sensors. When somebody enters the house it just checks and i didn't experience any mistakes for the past few weeks. The range is about 20 meters inside the house (trough some tricky walls). I don't know about the Thrust but i suspect the range of the thrust is way less. The conceptronics device is for about 12 euro, so it seems a better deal.

I just coupled it to my smoke detector. After 1 minute of no bluetooth device and strange activity the alarm will trigger. Hopefully that scares away the intruder ;).

geho
Posts: 40
Joined: Thursday 08 August 2013 22:30
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: Script examples (Lua)

Post by geho » Saturday 07 September 2013 21:07

I would like to have the "today usage" of the energy meter (Youless) available in LUA. I can access the current usage and total usage (meterstand) but not today's like is mention on the webpage.

Does anyone know if that is availabe?

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

Re: Script examples (Lua)

Post by Keptenkurk » Sunday 08 September 2013 0:20

This example switches my Woonveilig alarmpanel (which is actually a rebranded CTC-1716 by Climax Tech) according to the state of a Domoticz switch.

The LUA script is triggered by the device MASTERSWITCH. When switched on, the Woonveilig panel will be armed. When switched off, the panel will be disarmed.
An additional light (Lampje bij Thermostaat) confirms the alarmpanel state visually.
Application: automatic arm/disarm based on being at home (mobile phone's WiFi or Bluetooth - see other examples in this forum) or scheduled.

file: ~/domoticz/scripts/lua/script_device_alarmpanel.lua

Code: Select all

commandArray = {}
if (devicechanged['MASTERSWITCH'] == 'On') then
        os.execute('/home/pi/domoticz/scripts/alarmpanel.sh arm')
        print('Alarmpanel armed')
        commandArray['Lampje bij thermostaat']='On'
end

if (devicechanged['MASTERSWITCH'] == 'Off') then
        os.execute('/home/pi/domoticz/scripts/alarmpanel.sh disarm')
        print('Alarmpanel disarmed')
        commandArray['Lampje bij thermostaat']='Off'
end
return commandArray


Switching of the Alarmpanel is performed by the shell script "alarmpanel.sh" which can take the argument 'arm', 'armhome', 'disarm', 'sirenon' or 'sirenoff'.
First a login is made to a general page. Then the requested POST is made to the web page where the alarmpanel arming state can be set.
When the login expires, every first POST command will fail with an autentication request page, therefore we first login before every POST command.

tip: To find out the URL and POST values of the page use Firefox with the Firebug plugin enabled to browse to the page. The debug output will show
exactly which GET and POST messages and parameters were called. This will enable you to control or read from virtually any device which offers a web interface.

EDIT: Additionally an extra argument is available: checkstate
This reads the current state of the panel (Arm, Home or Disarm) and sets/resets a dummy switch in Domoticz.
I run this feature every minute by cron. This now reflects my "at home" state and consequently switch my close-in boiler off when not at home.
(need to build a businesscase for this hobby :roll: )

file: ~/domoticz/scripts/alarmpanel.sh

Code: Select all

#!/bin/bash

########################################################################################
### Woonveilig script v1.2 beta added checkstate option to request current armed state
###
### Domoticz <--> Woonveilig interface script
###
### Usage:
### alarmpanel arm
### puts the Woonveilig alarmpane is the Armed state
###
### alarmpanel armhome
### puts the Woonveilig alarmpanel in the Armed & at Home state
###
### alarmpanel disarm
### puts the Woonveilig alarmpanel in the Disarmed state
###
### alarmpanel sirenon
### sounds the siren (and maybe the remote siren too) of the Woonveilig alarmpanel
###
### alarmpanel sirenoff
### silences the siren (and maybe the remote siren too) of the Woonveilig alarmpanel
###
### alarmpanel checkstate
### reads the current armed state of the Woonveilig alarmpanel and changes a Domoticz switch
### to On when disarmed or armed & home and to Off when armed.
###
########################################################################################

if [ $#  -lt 1 ]
then
        echo "Usage: alarmpanel {arm | armhome | disarm | sirenon | sirenoff | checkstate}"
        exit
fi

### USER CONFIGURABLE PARAMETERS
PANEL="192.168.1.133:80"                # Alarm panel IP:PORT (find this in your router DHCP scope)
PANEL_USR="admin"                       # Alarm panel username (default admin)
PANEL_PASS="admin1234"                  # Alarm panel password (default admin1234)
DZSERVER="192.168.1.95:8080"            # Domoticz server IP:PORT
AT_HOME="28"                            # Idx of dummy switch which reflects at home state
                                        # (find this in Domoticz|Devices|Idx column)
### END OF USER CONFIGURABLE PARAMETERS

### First login to alarmpanel
/usr/bin/curl -u $PANEL_USR:$PANEL_PASS -s http://$PANEL/setting/index.htm >/dev/null

### Then issue appropriate command
case "$1" in

arm)            echo "Arm Alarmpanel"
                /usr/bin/curl -d "mode=0" -u $PANEL_USR:$PANEL_PASS -s http://$PANEL/action/panelCondPost >/dev/null
                ;;

armhome)        echo "Armhome Alarmpanel"
                /usr/bin/curl -d "mode=1" -u $PANEL_USR:$PANEL_PASS -s http://$PANEL/action/panelCondPost >/dev/null
                ;;

disarm)         echo "Disarm Alarmpanel"
                /usr/bin/curl -d "mode=2" -u $PANEL_USR:$PANEL_PASS -s http://$PANEL/action/panelCondPost >/dev/null
                ;;

sirenon)        echo "Siren On"
                /usr/bin/curl -d "sndsiren_onoff=0" -u $PANEL_USR:$PANEL_PASS -s http://$PANEL/action/sndSirenPost >/dev/null
                ;;

sirenoff)       echo "Siren Off"
                /usr/bin/curl -d "sndsiren_onoff=1" -u $PANEL_USR:$PANEL_PASS -s http://$PANEL/action/sndSirenPost >/dev/null
                ;;

### Read current state webpage
### And watch for Arm, Home or Disarm in the answer
### Set (dummy) switch to On or Off as required

checkstate)     strPanelState=`/usr/bin/curl -u $PANEL_USR:$PANEL_PASS -s http://$PANEL/action/panelCondGet`
                if [[ $strPanelState == *\"Arm\"* ]]
                then
                        echo "State is Armed"
                        /usr/bin/curl "http://$DZSERVER/json.htm?type=command&param=switchlight&idx=$AT_HOME&switchcmd=Off&level=0"
                else
                  if [[ $strPanelState == *\"Disarm\"* ]]
                  then
                        echo "State is Disarmed"
                        /usr/bin/curl "http://$DZSERVER/json.htm?type=command&param=switchlight&idx=$AT_HOME&switchcmd=On&level=0"
                  else
                    if [[ $strPanelState == *\"Home\"*  ]]
                    then
                        echo "State is Armed Home"
                        /usr/bin/curl "http://$DZSERVER/json.htm?type=command&param=switchlight&idx=$AT_HOME&switchcmd=On&level=0"
                    else
                        echo "No matched state found"
                    fi
                  fi
                fi

                ;;

*)              echo "Invalid argument. Usage: alarmpanel {arm | armhome | disarm | sirenon | sirenoff | checkstate}"
                ;;

esac

### Done


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

Re: Script examples (Lua)

Post by Dynamic » Thursday 19 September 2013 7:59

mbliek wrote:
Dynamic wrote:What type did you use? And was it easy to install? I'm not a experienced linux-user, but this function looks really great!
Well I was a Trust Bluetooth 3.0 USB adapter (10 meter range). But it was not very reliable. (maybe because it doesn't support HCI mode?)
So I bought a ICIDU 4.0 bluetooth dongle (http://www.replacedirect.nl/product/P01 ... 3godpWMAsA) It is much better (50 meter range) and supports HCI mode.

I'm not a experienced linux-user as well, I just copy and paste the code from internet :) and it worked.

If you need any help, just ask.
I think I might need your help... I installed the ICIDU, I can scan for present devices (it found my iPhone), but your script doesn't work. This is my code:

Code: Select all

    #!/bin/bash
     

    # Domoticz server
    SERVER="192.168.1.5"
     
    check=`hcitool name AA:BB:CC:DD:EE:FF`

    echo $check
    if expr "$check" '=' iphone van Mij
    then
           echo "iPhone is binnen bereik"
           # Send data
          curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=switchlight&idx=60&switchcmd=On"
    else
           echo "iPhone is buiten bereik"
           # Send data
          curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=switchlight&idx=60&switchcmd=Off"
    fi
Where AA:BB:CC:DD:EE:FF is my iPhone (don't have it's MAC present right now).

It crashes on 'iPhone van mij'.

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

Re: Script examples (Lua)

Post by mbliek » Thursday 19 September 2013 12:28

Dynamic wrote:
mbliek wrote:
Dynamic wrote:What type did you use? And was it easy to install? I'm not a experienced linux-user, but this function looks really great!
Well I was a Trust Bluetooth 3.0 USB adapter (10 meter range). But it was not very reliable. (maybe because it doesn't support HCI mode?)
So I bought a ICIDU 4.0 bluetooth dongle (http://www.replacedirect.nl/product/P01 ... 3godpWMAsA) It is much better (50 meter range) and supports HCI mode.

I'm not a experienced linux-user as well, I just copy and paste the code from internet :) and it worked.

If you need any help, just ask.
I think I might need your help... I installed the ICIDU, I can scan for present devices (it found my iPhone), but your script doesn't work. This is my code:

Code: Select all

    #!/bin/bash
     

    # Domoticz server
    SERVER="192.168.1.5"
     
    check=`hcitool name AA:BB:CC:DD:EE:FF`

    echo $check
    if expr "$check" '=' iphone van Mij
    then
           echo "iPhone is binnen bereik"
           # Send data
          curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=switchlight&idx=60&switchcmd=On"
    else
           echo "iPhone is buiten bereik"
           # Send data
          curl -s -i -H "Accept: application/json" "http://$SERVER/json.htm?type=command&param=switchlight&idx=60&switchcmd=Off"
    fi
Where AA:BB:CC:DD:EE:FF is my iPhone (don't have it's MAC present right now).

It crashes on 'iPhone van mij'.
Is iPhone van mij the name of your iPhone?

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

Re: Script examples (Lua)

Post by Keptenkurk » Thursday 19 September 2013 14:00

@piotr
I only have RFXCOM for 433MHz. The Woonveilig sensors operate at 868 MHz and don't know if they are recognised by RFX or Domoticz. I just talk to Woonveilig through the web interface.

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

Re: Script examples (Lua)

Post by Dynamic » Thursday 19 September 2013 16:04

mbliek wrote:Is iPhone van mij the name of your iPhone?
Yes it is. I tried to put the name between "", but that didn't help. I can try to rename my iPhone, but i'd rather keep this name.

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

Re: Script examples (Lua)

Post by mbliek » Thursday 19 September 2013 16:11

change SERVER="192.168.1.5" to SERVER="192.168.1.5:8080" (if your port is 8080)

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

Re: Script examples (Lua)

Post by Dynamic » Thursday 19 September 2013 19:26

mbliek wrote:change SERVER="192.168.1.5" to SERVER="192.168.1.5:8080" (if your port is 8080)
I'm running domoticz on port 80...

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests