Egyras / HeishaMon

Panasonic Aquarea air-water H, J, K and L series protocol decrypt
217 stars 113 forks source link

[Feature Request] Extend rules with MQTT subscriptions #497

Open martin31821 opened 2 weeks ago

martin31821 commented 2 weeks ago

I'd like to propose an addition to the rule engine in heishamon, namely the possibility to subscribe to MQTT topics and run rules when a message is received on the topic, as well as the possibility to react to connection lost/reconnection events.

Possible usecases might be:

I'm imagining a rule like this:

on System#Boot then 

  # mqttSubscribe takes two parameters, first the topic to subscribe to 
  # and a target callback to invoke when a message is subscribed 
  mqttSubscribe("electricity/currentprice", 10)  

end 

# When a message is received that's been registered with callback number 10
on MQTT#10 then 
  # MQTT topic for current message is stored in @MQTT_Topic 
  if @MQTT_Topic == "electricity/currentprice" then 
    # Value shall be a float / number ? 
    # Available in @MQTT_Value 
    if @MQTT_Value < 0.28 && @DHW_TEMP < 45 then 
      @SetDHW_Target_Temp = 55 
    elseif @MQTT_Value > 0.50
      @SetDHW_Target_Temp = 35
    end
  end 
end 

# React to connection loss from broker
on MQTT#lost then 
  @SetDHW_Target_Temp = 45 
end 

What do you think of such an extension?

stumbaumr commented 1 week ago

If you already have a MQTT broker you might as well have a Home Assistant - more complex rules should go there with elaborate long term logging capabilities...

martin31821 commented 6 days ago

I do agree with you on the long term logging, although I have mine running in grafana/prometheus/mimir.

I was thinking to run more logic directly on device in order to have a sane fallback in case any of the more complex rules fails, thus also the handling of MQTT#lost.