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