I’ve been diving into the world of smart home automation lately, and I wanted to share my experience using Blockly to create a simple yet effective heating system indicator. If you’re new to Blockly or looking to enhance your home automation setup, this guide might be just what you need!
The Goal: Heating Status Indicator
I recently installed a Homematic heating valve in my kitchen and wanted a clear visual indicator showing whether the heating was on or off. The valve itself doesn’t provide a direct on/off state, but it does report the opening level as a dimmer item. My plan was to use this data to trigger a status update in my OpenHAB interface.
Blockly Setup: A Simple Yet Effective Solution
I decided to use Blockly because it’s user-friendly and allows for quick rule creation without diving deep into code. Here’s how I set it up:
-
Create a Dummy Item: I started by creating a dummy item (
HeizungKuche_Status) to hold the heating status. This item would be updated based on the valve’s opening level. -
Blockly Rule Creation: Using Blockly, I created a rule that checks the opening level of the valve (
HeizungKuche_Level). If the level is above 0, it sets the status item toON. If it’s 0, it sets it toOFF.
-
Debugging and Testing: Initially, I encountered an issue where the rule kept triggering the
elsepart, indicating that Blockly wasn’t correctly interpreting the dimmer value as a number. After some research, I realized that converting the item to aNumbertype and using JavaScript rules provided a more reliable solution.
JavaScript Rule for Reliability
For those comfortable with a bit of coding, here’s the JavaScript rule I ended up using:
javascript
var logger = Java.type(‘org.slf4j.LoggerFactory’).getLogger(‘org.openhab.rule.’ + ctx.ruleUID);
if (parseFloat(‘HeizungKuche_Level’) > 0) {
events.postUpdate(‘HeizungKuche_Status’, ‘ON’);
} else if (parseFloat(‘HeizungKuche_Level’) == 0) {
events.postUpdate(‘HeizungKuche_Status’, ‘OFF’);
} else {
logger.info(itemRegistry.getItem(‘HeizungKuche_Level’).getState());
}
Lessons Learned
While Blockly is fantastic for quick and simple automation, it does have limitations, especially when dealing with item types like dimmers. Always consider converting items to Number types for more reliable rule execution. Additionally, don’t hesitate to mix Blockly with JavaScript rules for more complex scenarios!
Final Thoughts
This project was a great way to get familiar with Blockly and OpenHAB’s rule engine. It’s satisfying to see the heating status clearly displayed, and it’s just one example of how automation can enhance your smart home experience. If you’re looking to try Blockly, start with simple projects like this and gradually tackle more complex automations!
Happy automating! ![]()