Online indicator for remote controllable power plugs in openHAB
Posted by
ads' corner
on
Saturday, 2021-01-09 Posted in [Ansible][Openhab]
Recently I installed a number of new power sockets (like this one). The Hue bridge can not only add each switch to a light group, but also reports each plug as a Thing in openHAB. There I thought it will be a nice touch if openHAB actually reports when it sees a device plugged in. The power socket has a LED which turns on when the plug is on. The Hue bridge reports OFFLINE and ONLINE. That’s useful.
The plan is to turn the LED light - and the power plug - on and off for a few second.
I have a number of power plugs, and I roll out the configuration using Ansible. Talk about creating configuration from configuration …
Configuration
Here is an example of my plug.yml which holds the configuration for each plug:
The Thing is offlineRule only sets the Thing back to OFF.
1
2
3
4
5
6
7
8
9
{% for p in plugs %}rule "{{ p['name'] }} goes Offline"whenThing "{{ p['id'] }}" changed from ONLINE to OFFLINEthenlogInfo("Power Plug Monitoring", "{{ p['name'] }} socket is offline"){{p['item_name'] }}.sendCommand(OFF)end{% endfor %}
Result/Example
Here is the entire Rule as it is deployed to openHAB, for one plug:
var Timer timer_Plug_ads_Desktop_left_side_2 =null
var Timer timer_Plug_ads_Desktop_left_side_4 =null
var Timer timer_Plug_ads_Desktop_left_side_final =null
rule "Plug ads Desktop left side comes Online"
when
Thing "hue:0010:00513E05C343:10" changed from OFFLINE to ONLINE
then
logInfo("Power Plug Monitoring","Plug ads Desktop left side socket came online")
Plug_ads_Desktop_left_side.sendCommand(OFF)
timer_Plug_ads_Desktop_left_side_2 = createTimer(now.plusSeconds(2),[|
Plug_ads_Desktop_left_side.sendCommand(ON)if(timer_Plug_ads_Desktop_left_side_2 !==null){
timer_Plug_ads_Desktop_left_side_2.cancel()
timer_Plug_ads_Desktop_left_side_2 =null}])
timer_Plug_ads_Desktop_left_side_4 = createTimer(now.plusSeconds(4),[|
Plug_ads_Desktop_left_side.sendCommand(OFF)if(timer_Plug_ads_Desktop_left_side_4 !==null){
timer_Plug_ads_Desktop_left_side_4.cancel()
timer_Plug_ads_Desktop_left_side_4 =null}])
timer_Plug_ads_Desktop_left_side_final = createTimer(now.plusSeconds(6),[|
Plug_ads_Desktop_left_side.sendCommand(ON)if(timer_Plug_ads_Desktop_left_side_final !==null){
timer_Plug_ads_Desktop_left_side_final.cancel()
timer_Plug_ads_Desktop_left_side_final =null}])
end
rule "Plug ads Desktop left side goes Offline"
when
Thing "hue:0010:00513E05C343:10" changed from ONLINE to OFFLINE
then
logInfo("Power Plug Monitoring","Plug ads Desktop left side socket is offline")
Plug_ads_Desktop_left_side.sendCommand(OFF)
end