Running OH 3.2 I plan to control (various) dimmers by a physical “ButtonBox”.
The buttons are connected via MQTT using Homie Convention. The box runs a menu with a hierarchical state machine, so it converts it input directly to command strings.
The whole project is planned as an example in a series of workshops explaining how to build the Button Box (FreeCAD → Laser cutting), programm it (Arduino, PlatformIO, Eclipse, MQTT/Homie, Use of state machines) and using it for home automation (OpenHAB). So I strive for a “cleanest” possible solution and want to avoid any “ugly” workarounds.
For some of my questions the answer probably is “this is how OpenHAB is designed”, but maybe these question then can be an idea for future improvements.
The current setup is:
- There is a channel and Item of Type Dimmer for the LED strip to control.
- There is a channel and item of Type String to receive “commands” from the ButtonBox, these include “TOGGLE”, “INCREMENT” or “DECREMENT”.
- There is a rule (jython) to read the command-string and forward it to the dimmer item. A “TOGGLE” command is changed to “ON” or “OFF” depending on current state of the target item.
This works fine, but there are some issues:
- The increment/decrement is only 1%
- There seems to be no toggle command for a Dimmer.
- It seems unnecessary to use a rule (use profiles instead)
- Even although the received command could really be a “Command” type, it is a normal “State” for OpenHab.
- This state needs to be reset to an “NoOp” (or “Idle”) state by a rule to recognize further commands.
So, my questions:
- Is there a way to increment or decrement an item or channel by more than one, when INCREMENT or DECREMENT command are received?
- I could change the inc/dec buttons to send their “pressed” state and use the
rawrocker-to-dimmer
profile. However, INCREMENT or DECREMENT every 500ms is WAY too slow (it would take 50s to reach 100%). So to use this approach: Is there a way to lower this delay? - Why there is no TOGGLE command for OnOffType? Is there any elegant workaround other than a rule? (e.g. own profiles using the script engine (preferrably python)).
- Is it possible to convert incoming MQTT strings directly to an OpenHab Command?
- What is the most elegant solution to have a rule that handles such “command strings” without unnecessary trigger for the “NoOp” state.
Thing/Channel configuration:
Thing mqtt:topic:kueche_thled "Küche Thermometer & LED" (mqtt:broker:IAmq) @ "Küche" {
Channels:
Type dimmer: LED_w "Arbeitsplatte weiß" [ stateTopic="homie/kueche_thled/LED-RGBW/w", commandTopic="homie/kueche_thled/LED-RGBW/w/set" ]
}
Thing mqtt:topic:coffeectrl "Kaffee Controller" (mqtt:broker:IAmq) @ "Küche" {
Type string: coffee_white_cmd "CoffeeCtrl Command White" [stateTopic="homie/CoffeeCtrl/RGBWCtrl/w_cmd" ]
}
item-Configuration:
String CoffeeWhiteCmd "Coffee ctrl command white" {channel="mqtt:topic:coffeectrl:coffee_white_cmd"}
Dimmer kueche_thled_LED_w "Arbeitsfläche weiß" (kueche_thled, gAutom_ALL_OFF) { channel="mqtt:topic:kueche_thled:LED_w" }
Rules:
from core.rules import rule
from core.triggers import when
@rule("receive command white from OP Box Kueche")
@when("Item CoffeeWhiteCmd changed")
def kuOpBoxWhite(event):
cmd = event.itemState.toString()
if cmd == "NoOp": return
targetItem = "thermo_ian_LED_w"
events.postUpdate("CoffeeWhiteCmd", "NoOp") # Reset Item to NoOp
if cmd == "TOGGLE":
cmd = "ON" if items[targetItem].as(OnOffType) == OFF else "OFF"
events.sendCommand(targetItem, cmd)
Teaser: Photo of the box (I hope this will be a reall “cool” project that I can finish soon - including workshop-capable documentation):