Hi all,
I'm pulling out my remaining hair with what I think should be a simple problem to solve.
I am using presence detection on my phone from a script running on my Asus router.
The script updates one of two virtual devices on either 2.4 or 5.0 Ghz network so that I can tell that my phone is in the house and which network it is connected to.
That works fine.
I have a further dummy device that is updated if either of the 2.4 or 5.0 dummies are on.
The problem is I want the dummy device to only turn on if it was previously off, for example right now if my phone switches from 2.4 to 5.0 the dummy device will be switched on again even though I am already home - I want this to only happen if it is already off...otherwise do not update.
I hope I have explained well.
Thanks in advance.
Toggle device?
Moderator: leecollings
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Toggle device?
Use the current state of the switch in a if block of your script.
Re: Toggle device?
Thanks Egregius, I was hoping to cheat it in Blockly but you are right..lua is the answer!
- Egregius
- Posts: 2582
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Toggle device?
Or any other language...
-
- Posts: 5
- Joined: Wednesday 07 September 2016 9:06
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Toggle device?
Hi
Would it be possible for you to share the script you use at your router?
Thanks
Would it be possible for you to share the script you use at your router?
Thanks
-
- Posts: 140
- Joined: Wednesday 17 December 2014 17:30
- Target OS: Linux
- Domoticz version: V3.8650
- Location: Jyväskylä, Finland
- Contact:
Re: Toggle device?
Whats the problem with blocky?theolsen wrote:The problem is I want the dummy device to only turn on if it was previously off, for example right now if my phone switches from 2.4 to 5.0 the dummy device will be switched on again even though I am already home - I want this to only happen if it is already off...otherwise do not update.
if dummy <> on and (dummy24 = on OR dummy5 = on) then
set dummy = on
else if dummy = on and dummy24 <> on AND dummy5 <> on
set dummy = off
end if
LXC(x64 Ubuntu Xenial), RFXtrx433E, MySensors
Re: Toggle device?
Of course, I cobbled it together from http://forum.micasaverde.com/index.php?topic=24084.0bloody2k wrote:Hi
Would it be possible for you to share the script you use at your router?
Thanks
I am sure it is far from efficient but it works for me and doesn't miss a beat.
Code: Select all
#!/bin/sh
WATCHDOG_SLEEP_SEC=10
MAC_ADDRESS_1=“nn:nn:nn:nn:nn:nn” # Ken
c1_last_state="0"
c3_last_state="0"
MAC_ADDRESS_2=“nn:nn:nn:nn:nn:nn” # Barbie
c2_last_state="0"
c4_last_state="0"
VERAURL1="http://192.168.1.65:8080/json.htm?type=command¶m=switchlight&idx=26&switchcmd="
VERAURL2="http://192.168.1.65:8080/json.htm?type=command¶m=switchlight&idx=27&switchcmd="
VERAURL3="http://192.168.1.65:8080/json.htm?type=command¶m=switchlight&idx=29&switchcmd="
VERAURL4="http://192.168.1.65:8080/json.htm?type=command¶m=switchlight&idx=28&switchcmd="
x=0
y=0
offcount1=0
offcount2=0
offcount3=0
offcount4=0
while sleep $WATCHDOG_SLEEP_SEC
do
if [ "$x" == 180 ]; then
x=0
c1_last_state="0"
c2_last_state="0"
c3_last_state="0"
c4_last_state="0"
fi
x=$(( $x + 1 ))
c1_new_state=`wl -i eth2 assoclist | grep $MAC_ADDRESS_1`
if [ "$c1_new_state" == "$c1_last_state" ] ; then
sleep 0
else
if [ "$c1_new_state" == "assoclist $MAC_ADDRESS_1" ]; then
c1_last_state="$c1_new_state"
wget -qs "http://192.168.1.65:8080/json.htm?type=command¶m=switchlight&idx=27&switchcmd=On"
offcount1=0
else
offcount1=$(( $offcount1 + 1 ))
fi
fi
c2_new_state=`wl -i eth2 assoclist | grep $MAC_ADDRESS_2`
if [ "$c2_new_state" == "$c2_last_state" ] ; then
sleep 0
else
if [ "$c2_new_state" == "assoclist $MAC_ADDRESS_2" ]; then
c2_last_state="$c2_new_state"
wget -qs "http://192.168.1.65:8080/json.htm?type=command¶m=switchlight&idx=26&switchcmd=On"
offcount2=0
else
offcount2=$(( $offcount2 + 1 ))
fi
fi
c3_new_state=`wl -i eth1 assoclist | grep $MAC_ADDRESS_1`
if [ "$c3_new_state" == "$c3_last_state" ] ; then
sleep 0
else
if [ "$c3_new_state" == "assoclist $MAC_ADDRESS_1" ]; then
c3_last_state="$c3_new_state"
wget -qs "http://192.168.1.65:8080/json.htm?type=command¶m=switchlight&idx=28&switchcmd=On"
offcount3=0
else
offcount3=$(( $offcount3 + 1 ))
fi
fi
c4_new_state=`wl -i eth1 assoclist | grep $MAC_ADDRESS_2`
if [ "$c4_new_state" == "$c4_last_state" ] ; then
sleep 0
else
if [ "$c4_new_state" == "assoclist $MAC_ADDRESS_2" ]; then
c4_last_state="$c4_new_state"
wget -qs "http://192.168.1.65:8080/json.htm?type=command¶m=switchlight&idx=29&switchcmd=On"
offcount4=0
else
offcount4=$(( $offcount4 + 1 ))
fi
fi
if [ $offcount1 -lt 6 ]; then
# give not responding devices 1 minute to respond
sleep 0
else
c1_last_state="$c1_new_state"
wget -qs "http://192.168.1.65:8080/json.htm?type=command¶m=switchlight&idx=27&switchcmd=Off"
offcount1=0
fi
if [ $offcount2 -lt 6 ]; then
sleep 0
else
c2_last_state="$c2_new_state"
wget -qs "http://192.168.1.65:8080/json.htm?type=command¶m=switchlight&idx=26&switchcmd=Off"
offcount2=0
fi
if [ $offcount3 -lt 6 ]; then
sleep 0
else
c3_last_state="$c3_new_state"
wget -qs "http://192.168.1.65:8080/json.htm?type=command¶m=switchlight&idx=28&switchcmd=Off"
offcount3=0
fi
if [ $offcount4 -lt 6 ]; then
sleep 0
else
c4_last_state="$c4_new_state"
wget -qs "http://192.168.1.65:8080/json.htm?type=command¶m=switchlight&idx=29&switchcmd=Off"
offcount4=0
fi
done
Last edited by theolsen on Thursday 03 November 2016 18:13, edited 1 time in total.
Re: Toggle device?
Good call, I really don't know why I wasn't thinking like that
Whats the problem with blocky?
if dummy <> on and (dummy24 = on OR dummy5 = on) then
set dummy = on
else if dummy = on and dummy24 <> on AND dummy5 <> on
set dummy = off
end if
Thanks
Who is online
Users browsing this forum: No registered users and 1 guest