I'll explain how to integrate those controls with openHAB for more practical use.
OpenHAB Binding Configuration
In order to run a linux script from within openHAB we need to first install the "Exec Binding".
There are a few examples on how to configure the exec binding but none of the examples worked for me. I ended up following this post to get the right combination of Things/Items/Sitemaps working to give the following result:
I'll go in to some more detail below on how I configured my Things/Items/Sitemap to get the units working.
There are a few peculiarities in working with the Bluetooth version of the Teptron Move with the command line functions. I've noticed the following inconsistencies:
I've tried a number of workarounds for this but so far I've had the most success with simply just retrying the command multiple times, but this has the issue of pausing the unit motion when the second/third command is resent. I'm not ready to give up on this one just yet, but I'm fast running out of ideas.
Copy the following lines in to the file and save the file:
Now make the script executable with the command:
This script accepts two input arguments:
Add the following lines:
The important part of the command here is the name of the Thing, in this case "Blinds_GF_Lounge_North" and "Blinds_GF_Lounge_South". These will need to match the name of the items we will create next.
Create a new .items file:
Add the following items:
Ensure the names of the defined items match the names of the things we defined previously.
Add the following lines where applicable:
If everything was working properly, pressing the buttons on the sitemap should command the move units to the open and closed positions.
Technically it should be possible to use a slider here to set the blind position, but I'm yet to work out how to do it.
Remember the following command is great to be able to debug any openHAB issues:
Exec Binding Installation |
There are a few examples on how to configure the exec binding but none of the examples worked for me. I ended up following this post to get the right combination of Things/Items/Sitemaps working to give the following result:
I'll go in to some more detail below on how I configured my Things/Items/Sitemap to get the units working.
There are a few peculiarities in working with the Bluetooth version of the Teptron Move with the command line functions. I've noticed the following inconsistencies:
- Sometimes the device does not respond and the command reports an error
- Other times the device responds and accepts the commands but does not move
- The time between receiving the accepted response and the device moving varies from immediate to ~5 seconds
I've tried a number of workarounds for this but so far I've had the most success with simply just retrying the command multiple times, but this has the issue of pausing the unit motion when the second/third command is resent. I'm not ready to give up on this one just yet, but I'm fast running out of ideas.
Move Control Script
Create a new script in the in the openHAB scripts folder: sudo nano /etc/openhab/scripts/teptron_move_control.sh
Copy the following lines in to the file and save the file:
#!/bin/sh
RESPONSE=""
# execute the command multiple times
#for i in 1 2 3
for i in 1
do
RESPONSE="$(/home/openhabian/development/csrmesh/bin/csrmesh-cli move --pin 8888 --dest 43:c5:5b:04:00:06 --objid $1 --position $2)"
echo "Response: ${RESPONSE}"
sleep 1
done
Now make the script executable with the command:
chmod +x /etc/openhab/scripts/teptron_move_command.sh
This script accepts two input arguments:
- The move unit we want to move
- The position to be moved to (0 to 255)
Test the command is working as expected, as an example use the command:
This will command unit 2 to move to the fully opened position.
/etc/openhab/scripts/teptron_move_command.sh 2 255
This will command unit 2 to move to the fully opened position.
Things Configuration
Create a new .things file for the blinds: sudo nano /etc/openhab/things/blinds.things
Add the following lines:
Thing exec:command:Blinds_GF_Lounge_North "Blinds" [ command="bash /etc/openhab2/scripts/teptron_move_control.sh 1 %2$s", interval=0, autorun=true ]
Thing exec:command:Blinds_GF_Lounge_South "Blinds" [ command="bash /etc/openhab2/scripts/teptron_move_control.sh 2 %2$s", interval=0, autorun=true ]
The important part of the command here is the name of the Thing, in this case "Blinds_GF_Lounge_North" and "Blinds_GF_Lounge_South". These will need to match the name of the items we will create next.
Items Configuration
Next we must define items that will take the input from the sitemap and send it as a parameter to the exec binding and execute the script:Create a new .items file:
sudo nano /etc/openhab/items/blinds.items
Add the following items:
String Blinds_GF_Lounge_North_Command "Blinds" { channel="exec:command:Blinds_GF_Lounge_North:input", autoupdate="false" }
String Blinds_GF_Lounge_South_Command "Blinds" { channel="exec:command:Blinds_GF_Lounge_South:input", autoupdate="false" }
Ensure the names of the defined items match the names of the things we defined previously.
Sitemap Configuration
We need to define a couple of switches with custom mapping to command the move units to the "Open" and "Close" positions: sudo nano /etc/openhab/sitemaps/default.sitemap
Add the following lines where applicable:
Switch item=Blinds_GF_Lounge_North_Command label="North Blinds" mappings=["255"="Open", "0"="Close"]
Switch item=Blinds_GF_Lounge_South_Command label="South Blinds" mappings=["255"="Open", "0"="Close"]
If everything was working properly, pressing the buttons on the sitemap should command the move units to the open and closed positions.
Technically it should be possible to use a slider here to set the blind position, but I'm yet to work out how to do it.
Remember the following command is great to be able to debug any openHAB issues:
tail -f /var/log/openhab2/openhab.log -f /var/log/openhab2/events.log
Hi Andrew,
ReplyDeleteThanks for the two posts in this series: they've been a big help!
I am running my OH server on a device without bluetooth, and this script on a RPi with bluetooth.
Do you know if it is possible to run a script remotely using the exec binding?
Cheers!
Glad you found it useful!
DeleteI'm not sure if there is an easy way to get that done, the only thing that comes to mind is to run a script from your OH server that connects to your RPi with bluetooth and runs the script. Seems like a messy way to go about it.
I've used UDP communication with python before, it was nice and simple, check out this example: https://wiki.python.org/moin/UdpCommunication
But again I'd think the better way would be to just get a bluetooth dongle and use it with the OH server. There might even be a good reason to do it if you read this github issue: https://github.com/nkaminski/csrmesh/issues/17
Seems like the dropout issues might be RPi bluetooth related
I've got it working using ssh.
DeleteI can't seem to get the exec command item to show in sitemap as a switch. I've triple checked my things/items/sitemap but I only see my blinds as a string in sitemap, not a switch.
Any further clues?
Hmm not sure, but take a look at my more recent post on using the exec binding with some examples
Deletehttps://andrew-klimovski.blogspot.com.au/2017/06/home-automation-openhab-exec2-binding.html
Hi, How did you go with this did you get it more consistent in the command working. Thinking of doing something similar?
ReplyDeleteHow good have you found the Move range for bluetooth? Has it been stable?
Thanks Brad.
I haven't really used it since this post so i can't say it's become more reliable.
DeleteThere was some conversation on the git repo issues tracker where I think someone said they were getting better reliability from an external Bluetooth adapter as opposed to the internal Bluetooth on the RPi. That was going to be my next thing to try.