For context: This thread is a much delayed response to the Wireless Temperature Sensor thread. The same general topic was also brought up in the Portable Remote Sensor thread and most recently in a comment on the thread about hardware availability.
The goal is to write documentation on how to customize the HestiaPi to be able to use one or more remote temperature and humidity sensors, either in place of or in addition to the sensor on the HestiaPi itself.
For this thread, I’d like to limit the discussion to sensors that speak MQTT. Other sensors can be handled separately.
HestiaPi remote sensing plan
The HestiaPi is configured to run an MQTT broker. If you’re not familiar with MQTT, InfluxDB has a pretty good page introducing it, but the main point is that MQTT clients publish (send) messages to a MQTT broker (server) and the broker notifies any clients that are subscribed.
In our case, we will create an OpenHAB “thing” and configure channels to listen to multiple MQTT topics (channels) for each attribute that we care about (temperature, humidity, barometric pressure, etc.). Each channel will be linked to an “Item”, which is where the data is stored.
After that is working, we should be able to update the “Rules” (javascript code) to implement whatever logic we want. The logic for when to turn on the heat/cooling could look at one temperature sensor during the day and another one at night. It could look at the last update time and decide to use the other sensor if it hasn’t gotten data recently enough. The sky is the limit, as long as you are willing and able to write some Javascript code.
Instructions
This is a draft of the short version of the instructions that I wrote to get remote temperature data into OpenHAB on the Hestia Pi ONE. When they’re refined a little more and some gaps filled in, I’ll make sure they get put on the wiki and in the manual in the official git repo.
Make an item to store the data
OpenHAB → PaperUI → Configuration → Items → (+)
- Name (can’t have spaces): livingroomtemp
- Label (human readable, can have spaces): Living Room Temperature
- Category (optional, leave blank)
- Type: Number
- Dimension: Temperature
- Parent groups: Sensors, Proxy
- Auto update: Enforce an auto update
Click the plus in the blue circle at the top to save.
Docs: Items | openHAB
Make a thing to represent the sensor
OpenHAB → PaperUI → Configuration → Things → (+) → MQTT Binding → Add manually → Generic MQTT Thing
- Name (human readable, can have spaces): Living room sensor
- Thing ID: livingroomsensor
- Location: Sensors
- Bridge selection: Mosquitto MQTT Broker
- (leave the rest blank)
Click the checkmark in the blue circle at the top to save.
Docs: Things | openHAB
Add channels to the thing
This example matches the Thing that was created in the previous example. The text below is for adding temperature. Repeat the process for humidity, barometric pressure and anything else you want to get from the sensor.
OpenHAB → PaperUI → Configuration → Things → Living room sensor → Channels (+)
- Channel type: Number Value
- Channel ID (no spaces): temp
- Label (human readable): Temperature
- MQTT State Topic: homemade_sensor/living_room/temperature
Typically, temperature/humidity sensors that support MQTT will let you specify the MQTT State Topics. If they do not, then you will need to make the topic in OpenHAB match whatever the sensor is configured to use.
The “MQTT State Topic” can be pretty much anything you want as long as you’re consistent, but the pattern in the example is a typical pattern. You may have other home made sensors in other rooms, or entirely different types of sensors.
Make an Item to hold the local temperature
We are going to have the new sensor update the temperature field that is shown on the LCD display and in the web UI, but we will want to make sure that the HestiaPi’s built-in temperature sensor doesn’t try to continue also updating this item.
We will create a new item that can hold the value obtained from the local sensor allowing us to continue to use it later, if we decide we want to.
OpenHAB → PaperUI → Configuration → Items → (+)
- Name (can’t have spaces): localtemp
- Label (human readable, can have spaces): Local Temperature
- Category (optional, leave blank)
- Type: String
- Parent groups: Sensors, Proxy
- Auto update: Enforce an auto update
Click the plus in the blue circle at the top to save.
Re-linking local sensor to new item
The item that holds the temperature is labeled “Temperature” and it is named “MyTemp”. We want to have our remote sensor update this item, but first we want to tell the local temperature sensor to stop updating this. We will then link the local temperature sensor to the Local Temperature item that we made for it previously.
OpenHAB → PaperUI → Configuration → Things → Temperature Sensor
Under channels, click the blue concentric circles to the left of the “Output” channel, then click the trash can icon to the right of the linked item “Temperature (MyTemp)”.
While still in the Output channel of the Temperature Thing: Next to Linked Items → (+)
- Profile: Default
- Item to link: Local Temperature (localtemp)
Click the Link button to save.
Change MyTemp type
OpenHAB → PaperUI → Configuration → Items → Temperature (MyTemp) → Pencil icon
Type: Number
Dimension:
Click the check mark in the blue circle at the top to save.
It’s important to leave the Dimension blank here. Setting it to Temperature will result in an incorrect conversion from Celsius to Fahrenheit (so it’ll convert 0F to 32F, which is obviously undesirable).
Link the channel to the item
MyTemp is not available under the default profile, so we have to switch to Follow and then put the Profile back to Default.
OpenHAB → PaperUI → Configuration → Things → Living room sensor
Under channels, click the blue concentric circles to the left of the Temperature channel.
- Profile: Follow
- Item to link: Temperature (MyTemp)
Then click on the concentric circles and edit the linked item to put the Profile back to Default.
Repeat this process to also link it to the “Living Room Temperature (livingroomtemp)” item.
Docs: Configuration though Paper UI | openHAB
Verify our work
This is just to test to verify the item is updated when the MQTT message is sent.
OpenHAB → PaperUI → Control → SENSORS
You should see the Items you added here (local temperature and living room temperature). The values will be missing (e.g. a NaN or a -). To set the temperature, SSH into the HestiaPi and run the following:
sudo apt install -y mosquitto-clients
mosquitto_pub -h localhost -p 1883 -t "homemade_sensor/living_room/temperature" -m "25.6"
Note: This can also be run from another machine and changing localhost
to the IP address of the HestiaPi.
As soon as that command is run, without refreshing the page, the living room temperature value should be updated. On the CONTROLS tab, you should also see the same temperature appear for the “Current Temperature” (Under "Sensors and Setpoints). If you look at the LCD on the HestiaPi, you should also see that same temperature there.
Open Questions
-
How can we make our sensor appear under OpenHAB → PaperUI → Control → SENSORS (instead of only being listed under OTHER)?(updated post to include this) -
Is the local thermostat UI hardcoded, or will changes in OpenHAB affect that UI?OpenHAB changes won’t affect the LCD UI - How can the main
OpenHAB -> Basic
UI page be updated (e.g., to display the additional sensor)
I do realize that the UI is the hard part with this feature request and that it’s likely nobody has direct answers to these questions, but even pointers to resources (blog posts, documentation, etc.) would be helpful.