Debian 12 (bookworm) image testing (v1.5-dev)

Wow, I certainly did not expect setting it to zero to be “on”. Thanks for testing that out for me.

I haven’t managed to make time to patch this up, but I expect it should just be a minor change to the rules (or maybe a script?). Once I think I have it figured out, I’ll post a change here that people can make for testing before I go off and re-build an entire new image.

That is not the case for my (crowdfunded) hardware.

Relays boot at low.

Setting it at 0, does nothing.

Setting it at 1, clicks and LED goes ON.

Shutting HestiaPi down by ssh (sudo shutdown -h now) turns relays off.

Maybe in a very old hardware the wiring was different but I’m pretty sure this is not the case now. Old wiring caused all relays to go high when you shutdown and till HestiaPi booted fully, but as I said this is very old. A few years before the Crowdfunding (2019).
Can you show us @cheeseyone1 your PCB and relay wiring?

Hi Hacker ,

Looking at my relays I unfortunately got a batch of active low . They change state fine and also on shutdown or loss of power the relays are off . I am using a generic pi hat for a breakout board

For setting of gpio I am using a bash script saved in usr/bin/pin_12 on or off which has

#!/bin/bash

/usr/bin/gpioset gpiochip0 12=1
the exec script can control the pin to do what I need it to do . I only need to call the scipt to turn the output on or off

In openhab paper I am using command to call the bash script for pin 12 on and pin 12 off

this is linked with a item I created control heat relay on and another one for off

Next was rule I created a trigger based off the heating pin state

and then send a command to the relay item I created relay on to on relay off to off

The same type of rule is created for heating pin = off to change the state of the relays to send the comand to launch exec script to pin12_off

I repeated this same process for pin 18

I am also using a bme680 sensor instead of the bme 280 to utilize the air quality portion of the chip . To do this I rewrote ( with the help of ai) the bme280.py file

to utilize this you must install adafruit bme680 libary and the paho-mqtt to get airquality to openhab along with items to store air quality in openhab

#!/usr/bin/env python3
import time
import requests
import board
import busio
import adafruit_bme680
import paho.mqtt.client as mqtt

----------------------------

OpenHAB REST API settings

----------------------------

OH_HOST = “http://localhost:8080
#ITEM_TEMP_C = “MyTemp”
ITEM_TEMP_F = “MyTemp”
ITEM_HUMI = “MyHumi”
ITEM_PRESS = “MyPressure”
ITEM_AIR_QUALITY = “MyAirQuality”
ITEM_AIR_QUALITY_CAT = “MyAirQualityCategory”

----------------------------

MQTT settings

----------------------------

MQTT_BROKER = “localhost”
MQTT_PORT = 1883
TOPIC_IAQ = “hestia/local/iaq”
TOPIC_IAQ_CAT = “hestia/local/iaq_category”

----------------------------

Initialize I2C and BME680

----------------------------

i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_bme680.Adafruit_BME680_I2C(i2c, address=0x76)

Optional sensor settings

sensor.sea_level_pressure = 1013.25
sensor.temperature_oversample = 8
sensor.humidity_oversample = 2
sensor.pressure_oversample = 4
sensor.gas_oversample = 1
sensor.set_gas_heater_temperature = 320 # °C
sensor.set_gas_heater_duration = 150 # ms
sensor.gas_heater_profile = 0

----------------------------

Helper function to update OpenHAB item

----------------------------

def update_item(item, value):
url = f"{OH_HOST}/rest/items/{item}/state"
headers = {“Content-Type”: “text/plain”}
try:
response = requests.put(url, data=str(value), headers=headers)
if response.status_code in [200, 202]:
print(f"Updated {item}: {value}“)
else:
print(f"Failed to update {item}: {response.status_code} {response.text}”)
except Exception as e:
print(f"Error updating {item}: {e}")

def readIAQ():
“”“Compute IAQ index 0-500 from gas resistance”“”
gas = sensor.gas
if gas is None:
return 0
GAS_MIN = 5000.0
GAS_MAX = 500000.0
gas = max(GAS_MIN, min(GAS_MAX, gas))
iaq = int((gas - GAS_MIN) / (GAS_MAX - GAS_MIN) * 500)
return iaq

def readIAQCategory(iaq):
“”“Return EPA-style IAQ category”“”
if iaq <= 50:
return “Good”
elif iaq <= 100:
return “Moderate”
elif iaq <= 150:
return “Unhealthy for Sensitive Groups”
elif iaq <= 200:
return “Unhealthy”
elif iaq <= 300:
return “Very Unhealthy”
else:
return “Hazardous”

----------------------------

Initialize MQTT client

----------------------------

mqtt_client = mqtt.Client()
mqtt_client.connect(MQTT_BROKER, MQTT_PORT, 60)

----------------------------

Main loop: read sensor and push values

----------------------------

while True:
temp_c = round(sensor.temperature, 1)
temp_f = round((temp_c * 9 / 5) + 32, 1)
humidity = round(sensor.humidity, 1)
pressure = round(sensor.pressure*0.029529980,2)

iaq = readIAQ()
iaq_category = readIAQCategory(iaq)

print(f"Temp C: {temp_c}, Temp F: {temp_f}, Humidity: {humidity}, Pressure: {pressure}, IAQ: {iaq} ({iaq_category})")

# Update OpenHAB items
# update_item(ITEM_TEMP_C, temp_c)
update_item(ITEM_TEMP_F, temp_f)
update_item(ITEM_HUMI, humidity)
update_item(ITEM_PRESS, pressure)
update_item(ITEM_AIR_QUALITY, iaq)
update_item(ITEM_AIR_QUALITY_CAT, iaq_category)

# Publish to MQTT
mqtt_client.publish(TOPIC_IAQ, iaq)
mqtt_client.publish(TOPIC_IAQ_CAT, iaq_category)

time.sleep(10)  # adjust the interval as needed

After getting script running I changed default.sitemap in /etc/openhab2/sitemaps and added

Frame label=“Environment” {
// Text item=MyPressure label =“Pressure [%s]”
Text item=MyAirQuality label=“Air Quality Index [%d]”
Text item=MyAirQualityCategory label=“Air Quality Category [%s]”

to get

}

I am positive that this is not the cleanest way to get up and running but I am seeing relays respond and airquality,temp and humidity change .

Still working on jsnode and how to display on screen . I was able to add IAQ to info page with number replacing where disk space was but thats it

Please share photo of your hardware. Im not sure I understand the relay wiring to the Pi

FyI the relays are sinking

pi 3 - What does setting output high or low mean in RPi.GPIO - Raspberry Pi Stack Exchange

Setting an output pin HIGH outputs ~3.3V; LOW ~0V.

Both have limited current sourcing/sinking capability ~16mA.

What happens (and what current flows) depends on the external connections.

In general current potentially will flow out of a HIGH pin and into a LOW pin.


Incidentally, the way you have wired 3.3V — resistor — LED — GPIO is the way most engineers would connect the circuit.
This requires the GPIO to be LOW to turn the LED ON.
This seems to confuse many beginners.

Thanks everyone for the resistor size, confirming that gpiod works, 1 is typically on and 0 is off, and all the other things from this thread.

Shell script needed

Here are my notes on what I looked at before I become convinced that a shell script will be needed the GPIO can not be controlled via /sys. I’m showing my work so others can correct me if I’m wrong.

Rules → Heating Control: Can see that it turns HeatingPin to ON or OFF.

Configuration → Items → Heating Pin: This is the item being controlled

Rules → Map a device to gpio pin: This is the rule that sends the new state to the pin (and the mapping is done in defaults.js). In the case of system in US mode and turning on the heat, that’d be going to Pin12.

/etc/openhab2/items/default.items: creates the Pin12 item and maps it to `gpio=”pin:12” (and it also creates the other 3 PinXX to GPIO mappings).

As best I can tell, at the end of the day, it’s the GPIO binding that is doing the actual turning on/off of the GPIO pin, and the documentation makes it clear that this requires /sys which is no longer around. I do acknowledge that in OpenHAB 5 (the current version at the time of writing), the GPIO binding has been updated to use pigpiod which based on the name is pretty clear it will use gpiod instead of /sys. However starting at v3, OpenHAB started requiring a newer version of Java, which requires a hardware floating point unit and the Pi Zero W doesn’t have that.

So that’s why I think we need a script if this image is going to work with the original hardware.

Experimental solution

To be honest, I still don’t understand how all these thing/channels/items/rules/commands all fit together in OpenHAB, even after reading the overview several times. But I was able to follow along the path of @cheeseyone1 with some slight modifications. I will list out the changes I made and then link to the repo where you can check out the config files.

  1. I created the same shell scripts, but I put them in ~pi/scripts/.
  2. Add an Item called Pin12on (type=Switch) which will activate the thing
  3. Add a “Command heat relay on” Thing (type=Exec) that will run the script
  4. Edit the Thing and clicked on the blue circle next to the “Running” channel and selected Pin12on as the item to link. This causes the script to run when a command is sent to pin12on.
  5. Repeat steps 2-4 with Pin12off
  6. Repeat steps 2-5 with Pin16on and Pin16off for second stage heating
  7. Edit the JS in “then…” clause of the “Heating Control” rule to command these pins when needed (details below)
  8. For EU mode, repeat steps 2-5 with Pin23on and Pin23 off for your heating to work.

The changes to the “then…” clause of the “Heating Control” are to load defaults.js and then look up the correct pin for your heat and so an events.sendCommand(pinItem + "on", ON); to turn whatever relay controls your heat on (it’s not the same for the US and EU modes).

If you’ve been making these changes along at home, at this point the heating should be functional (including 2nd stage heating if that’s enabled).

Getting the new rules

If you are running the test image, you can get the new rules by checking out my fork of the repo

git clone https://github.com/hestiahacker/hestia-touch-openhab.git
cd hestia-touch-openhab
sudo rsync -av ./var /var
sudo rsync -av ./etc /etc
sudo rsync -av ./home /home

Do note that I haven’t tested restoring these files, and I haven’t tested things out in EU mode yet. But I did test out Heating, 2nd stage heat, fan and cooling. If the files can be moved from my checkout to other machines, and I didn’t miss anything, you should be able to reproduce this.

I think I missed a step .I modified Default items to pull up script based on on of condition of pin

// var logger = Java.type(“org.slf4j.LoggerFactory”).getLogger(“org.eclipse.smarthome.model.script.rules.backup”);
//
// var ExecUtil = Java.type(“org.eclipse.smarthome.io.net.exec.ExecUtil”);
// var r1 = ExecUtil.executeCommandLineAndWaitResponse(“echo ‘wait for result’”, 5000);
//
// var ScriptExecution = Java.type(“org.eclipse.smarthome.model.script.actions.ScriptExecution”);
// var DateTime = Java.type(“org.joda.time.DateTime”);
// var runme1 = function(){ logInfo(“Native Quartz Timer completed”); }
// var timer1 = ScriptExecution.createTimer( DateTime.now().plusSeconds(5), runme1);
//
//var OPENHAB_CONF = Java.type(‘java.lang.System’).getenv(‘OPENHAB_CONF’);
//load(OPENHAB_CONF + ‘/automation/lib/hestia/utils.js’);
//load(OPENHAB_CONF + ‘/automation/lib/hestia/defaults.js’);
//Switch Pin12 { gpio=“pin:12” }
//Switch Pin16 { gpio=“pin:16” }
//Switch Pin18 { gpio=“pin:18” }
//Switch Pin23 { gpio=“pin:23” }

Switch Pin12 “Pin12” { exec=“>[ON:/bin/bash /usr/local/bin/pin12_on.sh] >[OFF:/bin/bash /usr/local/bin/pin12_off.sh]” }
Switch Pin16 “Pin16” { exec=“>[ON:/bin/bash /usr/local/bin/pin16_on.sh] >[OFF:/bin/bash /usr/local/bin/pin16_off.sh]” }
Switch Pin18 “Pin18” { exec=“>[ON:/bin/bash /usr/local/bin/pin18_on.sh] >[OFF:/bin/bash /usr/local/bin/pin18_off.sh]” }
Switch Pin23 “Pin23” { exec=“>[ON:/bin/bash /usr/local/bin/pin23_on.sh] >[OFF:/bin/bash /usr/local/bin/pin23_off.sh]” }

Has anyone had a chance to check out modifications and confirm that they work? I want to make sure I didn’t miss committing any files, or commit something that is not portable to other HestiaPi devices. Instructions on how to get them for testing are here.

I haven’t been able to make the image run properly. Even with the steps you provided, relays do not get triggered (at all). UI (LCD + Web) gets updated but relays dont.