semaro
(Sebastian)
February 3, 2017, 12:44pm
23
Hi all,
I used the old exec binding-syntax to control relais via some sort of âinit-scriptâ.
Switch so_pin29 "Schalter 29" {exec=">[ON:/opt/openhab/scripts/relais.sh on] >[OFF:/opt/openhab/scripts/relais.sh off] <[/opt/openhab/scripts/relais.sh stat:6000:REGEX((.*?))]"}
I just donât see, how i should rebuild this with the new exec-syntax.
I tried the following:
Thing:
exec:command:relais29office [command="/opt/openhab/scripts/relais.sh %2$s", transform="REGEX((.*?))", autorun=false]
and then the item:
Switch so_pin29 "Schalter 29" {channel="exec:command:relais29office:run"}
first i realized is, that the switch only run the script in the case it is put âONâ ⊠and nothing in the case it is put âOFFâ
1 Like
HI,
so itâs not possibile to use exec binding with Switch item by executing one script for ON and another one for OFF ?
Is it possibile to run older 1.8 exec binding under openhab 2.0 ?
Regars
web
(Andi)
February 11, 2017, 9:14pm
25
You can decide in your script what happens.
Here an example:
#!/bin/bash
if [ â$1â = âoffâ ] || [ â$1â = â0â ];
then
// do something
else
// do something else
fi
Hello to all,
has anyone solved the problem?
I coded now:
.things:
Thing exec:command:steckdoseG2 [command="/opt/rc-switch/433Utils/RPi_utils/steckdose1.sh %2$s", transform="REGEX((.*?))", autorun=false]
.items:
Switch stecker {channel="exec:command:steckdoseG2:run"}
steckdose1.sh
#!/bin/sh
if [ "$1" = "off" ] || [ "$1" = "0" ] || [ "$1" = "OFF" ]; then
/opt/rc-switch/433Utils/RPi_utils/SteckdoseG2 15 0
else
/opt/rc-switch/433Utils/RPi_utils/SteckdoseG2 15 1
fi
Can anyone help me with this problem?
Thank you.
Temar
(Alex)
February 14, 2017, 5:20pm
27
This is a simplified version of what Iâm using to start/stop my NAS:
.things
Thing exec:command:device-nas-control [ command="/path/to/script %2$s", interval=0, autorun=true ]
.items
String network_device_nas_switch "NAS" { channel="exec:command:device-nas-control:input", autoupdate="false" }
.sitemap
Switch item=network_device_nas_switch mappings=[ "ON"="ON", "OFF"="OFF" ]
This will either send âONâ or âOFFâ to the script provided as âcommandâ.
Thanks, but i get this error:
[ERROR] [hab.binding.exec.handler.ExecHandler] - An exception occurred while formatting the command line with the current time and input values : âFormat specifier â%2$sââ
Can you help? Thanks.
Temar
(Alex)
February 14, 2017, 5:50pm
29
Honestly, no idea. I found my working configuration by searching the forums. I do not really understand the OH2 configuration concepts yet. Here is an intermediate version which actually worked at the time of writing but had some limitations: Trigger Exec Binding switch with HUE Emulation [SOLVED]
My current configuration is much more complex but I can post it if you need it.
maybe it will helps⊠that will be nice
Alex, the script of your link works fine
THANK YOU!!!
Temar
(Alex)
February 14, 2017, 5:56pm
32
Ok, here we go. That configuration allows me to start my NAS using the Amazon Echo and it actually represents the current state of the switch by querying if the device is online:
.things
Thing exec:command:device-nas-control âNAS Control Commandâ [ command="/home/openhab/bin/device-nas %2$s", interval=0, timeout=10, autorun=true ]
Thing exec:command:device-nas-status âNAS State Commandâ [ command="/home/openhab/bin/device-nas status", interval=20, timeout=5 ]
.items
String network_device_nas_control âNAS Controlâ { channel=âexec:command:device-nas-control:inputâ, channel=âexec:command:device-nas-status:outputâ, autoupdate=âfalseâ }
String network_device_nas_status âNAS Statusâ { channel=âexec:command:device-nas-status:outputâ }
Switch network_device_nas_switch âNASâ (group_location_livingroom) [ âSwitchableâ ]
.sitemap
Switch item=network_device_nas_switch
.rules
rule "NAS Switch"
when
Item network_device_nas_switch changed
then
logInfo("Network", "Switching NAS " + network_device_nas_switch.state.toString + ": " + network_device_nas_control.state.toString)
network_device_nas_status.postUpdate(network_device_nas_switch.state.toString)
network_device_nas_control.sendCommand(network_device_nas_switch.state.toString)
end
rule "NAS State"
when
Item network_device_nas_status changed
then
logInfo("Network", "Switching NAS " + network_device_nas_status.state.toString + ": " + network_device_nas_control.state.toString)
network_device_nas_switch.postUpdate(network_device_nas_status.state.toString)
network_device_nas_control.sendCommand(network_device_nas_status.state.toString)
end
1 Like
benhelps
(Ben Helps)
May 18, 2017, 1:32pm
33
Any idea if thereâs been a resolution of this problem yet? (exec 2 requiring String objects and no longer working with Number objects)?
Iâm trying to migrate from OH1.8 to OH2 but I canât bring over all my sensor data as Numbers, and every attempt to parse the Strings into Floats etc fails.
1 Like
s4ndst0rm
(Dominik Benner)
June 19, 2017, 1:43pm
34
Same here. Only String works⊠Number does not work.
rtvb
(Robert)
August 20, 2017, 6:40am
35
My current workaround is to create a stub String item that is bound to the exec binding channel and a second Number item that is populated from the String by a simple rule.
benhelps
(Ben Helps)
August 20, 2017, 8:49am
36
Yeah this is what Iâve been doing too , though itâs a bit ugly having a hundred or so lines of code just parsing each string into a number
rtvb
(Robert)
August 21, 2017, 4:35am
37
Just wondering. Would using a generic lambda function reduce the amount of code to maintain?
Lucan
(Lucan)
January 10, 2018, 9:39pm
38
Hello Alex,
could you also please provide the script that you are running?
Thank you very mich
Temar
(Alex)
January 11, 2018, 7:07pm
39
Hello Lucan,
here you go:
#!/bin/bash
THIS_NAME="$(basename "${0}")"
HOST_USER="openhab"
HOST_NAME="nas.home.lan"
HOST_MAC="xx:xx:xx:xx:xx:xx"
case "${1}" in
[oO][nN])
exec sudo /usr/sbin/etherwake "${HOST_MAC}" >/dev/null 2>&1
;;
[oO][fF][fF])
exec ssh -o ConnectTimeout=3 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -l "${HOST_USER}" "${HOST_NAME}" "sudo /sbin/poweroff" >/dev/null 2>&1
;;
[sS][tT][aA][tT][uU][sS])
ping -c 1 -W 1 "${HOST_NAME}" >/dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "ON"
exit 0
fi
echo "OFF"
exit 1
;;
*)
echo
echo "Usage: ${THIS_NAME} <on|off|status>"
echo
exit 1
;;
esac
exit 0
1 Like
Lucan
(Lucan)
January 11, 2018, 9:05pm
40
Temar:
.things
Thing exec:command:device-nas-control âNAS Control Commandâ [ command=â/home/openhab/bin/device-nas %2$sâ, interval=0, timeout=10, autorun=true ]
Thing exec:command:device-nas-status âNAS State Commandâ [ command=â/home/openhab/bin/device-nas statusâ, interval=20, timeout=5 ]
.items
String network_device_nas_control âNAS Controlâ { channel=âexec:command:device-nas-control:inputâ, channel=âexec:command:device-nas-status:outputâ, autoupdate=âfalseâ }
String network_device_nas_status âNAS Statusâ { channel=âexec:command:device-nas-status:outputâ }
Switch network_device_nas_switch âNASâ (group_location_livingroom) [ âSwitchableâ ]
.sitemap
Switch item=network_device_nas_switch
.rules
rule âNAS Switchâ
when
Item network_device_nas_switch changed
then
logInfo(âNetworkâ, "Switching NAS " + network_device_nas_switch.state.toString + ": " + network_device_nas_control.state.toString)
network_device_nas_status.postUpdate(network_device_nas_switch.state.toString)
network_device_nas_control.sendCommand(network_device_nas_switch.state.toString)
end
rule âNAS Stateâ
when
Item network_device_nas_status changed
then
logInfo(âNetworkâ, "Switching NAS " + network_device_nas_status.state.toString + ": " + network_device_nas_control.state.toString)
network_device_nas_switch.postUpdate(network_device_nas_status.state.toString)
network_device_nas_control.sendCommand(network_device_nas_status.state.toString)
end
Thank you so much! Iâve made a few changes so it fits my needs and everything works perfectly
Fichte07
(Fichte07)
February 6, 2018, 8:43pm
41
Switching from Number to String also solved the problem for meâŠ
Josar
(Josar)
February 11, 2018, 8:51am
42
I think there will be a solution for that in the next version oft the exec binding.
I use one rule for all strings to convert them.
It only needs one additional line for each item. And this will be reduced in future to only one group, have a look here.
This tutorial is based on this , this , this and a lot of threads and tutorials i had to read till i got it working.
I try to give a step by step Tutorial how to get a temperature chart with OpenHAB2 and the ExecBinding 2 using the RRD4J database for persistency.
I will not explain everything in detail, please read this post to get an basic understanding of how OpenHAB works. And use the tutorials and the manual to get deeper insight of how the different parts work.
Now to read out the CPU tempâŠ