In a more complex openHAB2 Rule I'm writing, I need to find out if a certain Item exist. If I try to access it when it does not exist, the Rule will fail. Not good.
I could pass in a parameter to the framework which builds the Rule, but that is cumbersome and requires changes on several places.
Let's see if I can have the Rule figure this out.
Continue reading "Does an openHAB Item exist?"
There are a number of ChromeCasts in our setup. I'm adding (physical) switches to turn displays on and off, and primarily control the volume. When I turn the display off, I also want the ChromeCast to stop doing whatever it is doing right now (stop streaming), and go back to the default application (for video CC).
The openHAB ChromeCast binding has a separate channel for that:
Switch chromecast_chromecast_dfb5af5187ce1135b276239130aef282_stop { channel="chromecast:chromecast:dfb5af5187ce1135b276239130aef282:stop" }
However since the channel is named "stop", it has to be "enabled" with "ON". Doesn't make sense? It is as it is:
chromecast_chromecast_dfb5af5187ce1135b276239130aef282_stop.sendCommand(ON)
And the result:
2021-01-18 17:13:20.305 [ome.event.ItemCommandEvent] - Item 'chromecast_chromecast_dfb5af5187ce1135b276239130aef282_stop' received command ON
2021-01-18 17:13:20.321 [nt.ItemStatePredictedEvent] - chromecast_chromecast_dfb5af5187ce1135b276239130aef282_stop predicted to become ON
2021-01-18 17:13:20.443 [vent.ItemStateChangedEvent] - chromecast_chromecast_dfb5af5187ce1135b276239130aef282_appName changed from <...> to UNDEF
2021-01-18 17:13:20.451 [vent.ItemStateChangedEvent] - chromecast_chromecast_dfb5af5187ce1135b276239130aef282_appId changed from <...> to UNDEF
2021-01-18 17:13:20.455 [vent.ItemStateChangedEvent] - chromecast_chromecast_dfb5af5187ce1135b276239130aef282_statustext changed from Casting: <...> to UNDEF
2021-01-18 17:13:20.457 [vent.ItemStateChangedEvent] - chromecast_chromecast_dfb5af5187ce1135b276239130aef282_idling changed from OFF to ON
2021-01-18 17:13:23.888 [vent.ItemStateChangedEvent] - chromecast_chromecast_dfb5af5187ce1135b276239130aef282_appName changed from UNDEF to Backdrop
2021-01-18 17:13:23.893 [vent.ItemStateChangedEvent] - chromecast_chromecast_dfb5af5187ce1135b276239130aef282_appId changed from UNDEF to E8C28D3C
If openHAB has a Persistence service configured, the time of the last Item update (and a couple other times) is available in Rules. This makes it quite handy to check if a certain item hasn't been updated in a long time. As example I have the Tankerkoenig Binding installed, and this data is persisted in InfluxDB. This way I can see historic gas prices in Grafana.
When the Telegram Bot answers the "/tanken" question, it appends the timestamp of the last gas prices update.
Continue reading "openHAB: timestamp from last Item update"
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.
Continue reading "Online indicator for remote controllable power plugs in openHAB"
In one of my openHAB rules I'm using a timestamp to track when an Item went offline. This is used in my monitoring to let the user (me) know how long the Item is already offline.
Background: we have a couple ChromeCasts in our network. When they are connected to a 5GHz Wi-Fi they are quite unstable and often loose the network connection. Usually the openHAB binding reconnects the device quickly, but it happens that the device stays offline. It might have something to do with the router, but nevertheless I want to know when things go offline.
For this I defined a virtual Switch as DateTime:
DateTime LivingRoom_OfflineSince "Offline Since [%tY-%tm-%td%tH:%tM:%tS]"
When the ChromeCast goes offline, this Switch is updated in a rule with the current time:
LivingRoom_OfflineSince.postUpdate( new DateTimeType() )
However resetting the DateTime switch when the item comes back online proved to be a small challenge, the documentation is unclear. People write online about "UnDeftype", "UNDEF", "(unknown)", "UnDefType.UNDEF", "UnDefType.NULL" and a couple more.
In the end it's quite easy:
LivingRoom_OfflineSince.postUpdate(NULL)
Just update the Item with NULL. Don't use sendCommand() here, you only want to update the Item, not send a new command to a virtual switch.
The openHAB rule system is not very helpful by pointing out when it's missing something, or when there is an error to actually point to the problem.
Was debugging an error message for a while and couldn't figure out what is wrong:
Configuration model '....rules' has errors, therefore ignoring it: [152,5]: no viable alternative at input '...'
The line number specified was somewhere else in the file, and had nothing to do with the rule in question. After removing almost everything from the rule, except a logInfo() message, the error still happened - and then it occured to me: I forgot to specify "Item".
My faulty code was:
rule "Rule Name"
when
Sensor_name received update
then
where it should have been:
rule "Rule Name"
when
Item Sensor_name received update
then
Error message totally not helpful ...
openHAB can integrate Google Calendars. The functionality is kind of limited, it can only see the current and the next calendar event, but in my case that is enough. More about the use case in another blog post.

There are three different calendar bindings available, let's have a quick look:
- CalDAV Personal Binding: this is a v1 binding, which means it will no longer work in the soon-to-be-released openHAB v3. Apparently this works with Google calendars, but has performance issues. It can show the current and next event.
- Google Calendar Scheduler: also a v1 binding. Needs more work for presense simulation, and additional bindings.
- iCalendar Binding: v2 binding, should work with v3. It can show the current and next event. That's the one I'm going to use.
Continue reading "Add a Google Calendar to openHAB"
openHAB rules files are lazy loaded. When a rule is used the first time, the entire rule file is loaded and compiled, which apparently is single-threaded and takes a couple seconds. Even on a reasonable powerful Rasperry Pi 4. This happens both after restarting openHAB and after changing the rules file. It also means that whatever the rule in question is supposed to do has to wait a couple seconds when requested for the first time. Imagine you have a light switch, enter a room, press the switch, and it takes 5-10 seconds until the light comes on.
To work around this problem, I add a piece of code in all rules files which triggers an immediate action right after loading the file. This way the rules file is already pre-loaded (which again takes a couple seconds, but likely at a time when the rule is not needed right now).
Continue reading "openHAB: faster loading of rules files"
A while ago someone mentioned "reminders" used in their home audio system, and I took that idea and implemented something similar in openHAB.
The basic idea is that I can send scheduled notifications to any audio sink openHAB is using, possibly more than one audio sink for one message. Also I want to differentiate between a simple audio sound, and text output.
For the text audio output I installed Text-to-Speech a while ago, this enables the ability to output text as audio in different languages. In addition I want an information when a reminder is "fired" in my Telegram control channel. As audio sink I'm mostly using ChromeCasts here, but anything openHAB can connect to is usable here.
Continue reading "Audio reminders in openHAB"
A while ago I integrated DWD warnings (Deutscher Wetterdienst) into our home automation system, and receive severe weather notifications ever since then. That works quite good, but it was missing a weblink with more details - or if you want to forward the warning to someone it would be useful to have a link to the warning as well. The DWD binding does not provide that piece of information, but it is easy enough to add - or so I thought.
Continue reading "openHAB, Telegram Bot and quoting URLs"
In my ongoing endeavor to improve our home, a while ago I added a notification when the washing machine and the dryer are finished. The notification is send to a Telegram channel. Over the summer vacation I added a number new ChromeCast Audio devices (Google no longer offers the Audio CC, if you need one get one now). One is placed in the kitchen. Not only can I listen to music while eating breakfast, I can also output notifications, by using the CC as an audio sink in openHAB.
To make that useful, I decided to use a Text-to-Speech system. openHAB offers a couple different TTS systems, however most of them need a cloud integration, and therefore a working Internet connection. The "Pico TTS" works standalone, and was my favorite choice for this implementation.
Continue reading "Text-to-Speech in openHAB"
In my previous blog post about "Tankerkönig" I explained the details of how to integrate this binding into openHAB and provide a Telegram interface.
Someone on the openHAB community forum pointed out that Telegram bots allow queries, where one can present the user with options, and the user only has to click on one of the options. That makes it easier to use, and less typing is required as well. I went ahead and implemented that.
Continue reading "openHAB and Tankerkönig gas prices + Telegram integration - Second iteration"
My plan is to reinstall openHABian on a bigger SDcard, and on a Raspberry Pi 4. The latest release (v1.5) supports the new Pi 4, and I decided it's time to do a fresh install, and see if all my Playbooks are still working.
Raspberry Pi 4 with Sectronics Armor (cooling) Case
As always, I'm searching my shell history for the right command how to install the image ... but came up empty.
Continue reading "Install openHABian image on Linux"
By default, openHAB only starts 5 threads to deal with execution of Rules. That's not a lot, and if all threads are busy, rules have to wait until a slot is free. This results in slow Rule response time.
This can be improved.
Continue reading "Improve openHAB Rules response time"
After figuring out if a ChromeCast is currently used, it was time to fix a long-standing problem. At home we don't have TVs, just "dumb" displays, and stream content using ChromeCasts. However a video ChromeCast never really turns off, but keeps the display running, using a "Backdrop" app. This app keeps showing pictures on the display when the ChromeCast is not used otherwise, effectively preventing any powersafe mode.
That's both annoying (who wants to have pictures shown in the living room or working room all night), and consumes energy. It's also intentional by Google. So far we had to turn the display on and off manually, which is inconvenient.
Continue reading "openHAB: Turn display on and off for a Video ChromeCast"