-
Notifications
You must be signed in to change notification settings - Fork 0
/
fhem-switch-status
57 lines (54 loc) · 1.95 KB
/
fhem-switch-status
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
#
# V0.1
# Source https://github.com/no-Legend/octoprint-psucontrol-fhem-script
# Based on https://github.com/kantlivelong/OctoPrint-PSUControl/blob/tplink/extra/scripts/tplink_smartplug/tplink-smartplug_wrapper.sh
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# See the COPYING file in the main directory for details.
#
V_IP="your ip here"
V_PORT="your port here"
V_USERNAME="your username here"
V_PASSWORT="your password here"
V_Devicename="your device here"
case $1 in
'on')
echo "Turning On..."
curl -s -k -u "$V_USERNAME:$V_PASSWORT" "https://$V_IP:$V_PORT/fhem?cmd=set%20$V_Devicename%20on&XHR=1"
exit $?
;;
'off')
echo "Turning Off..."
curl -s -k -u "$V_USERNAME:$V_PASSWORT" "https://$V_IP:$V_PORT/fhem?cmd=set%20$V_Devicename%20off&XHR=1"
exit $?
;;
'sense')
relay_state=$(curl -s -k -u "$V_USERNAME:$V_PASSWORT" "https://$V_IP:$V_PORT/fhem?cmd=list%20$V_Devicename%20state" | grep $V_Devicename | grep -o 'on\|off' | sed 's/on/1/g' | sed 's/off/0/g')
if [ $relay_state -eq 1 ]
then
echo "On"
exit 0
elif [ $relay_state -eq 0 ]
then
echo "Off"
exit 1
else
echo "Unknown Error"
exit 1
fi
;;
*)
echo "Usage $0: {on|off|sense}"
exit 1
esac