Generic Thermostat MQTT Posts

Greetings…

Have been using the generic thermostat function for some weeks now and it is working perfectly… except I cannot workout how to initiate MQTT posts when the fan is on and off.

If I were to guess, I’d say the generic thermostat function is bypassing the automation and just using the switch.fanrelay to turn the fan on and off.

Prior to using the generic thermostat function I was using a more rudimentary ‘manual’ thermostat automation, and I was able to send MQTT posts. Here’s what’s inside my automations.yaml file for the ‘manual’ fan on and fan off I created.

alias: Start Fan
  description: Star Fan Climate Control Based on Temperature and Damper Status
  trigger:
  - platform: state
    entity_id: switch.damperrelay
    from: 'off'
    to: 'on'
  condition: []
  action:
  - service: climate.turn_on
    target:
      entity_id: climate.studiofan
  - service: mqtt.publish
    data:
      topic: HomeAssistant/Studio/Fan/Status
      payload: '1'
  mode: single

I also have a Stop Fan automation, here it is…

alias: Stop Fan
  description: Stop Fan Climate Control Based on Damper Status
  trigger:
  - platform: state
    entity_id: switch.damperrelay
    from: 'on'
    to: 'off'
  condition: []
  action:
  - service: climate.turn_off
    target:
      entity_id: climate.studiofan
  - service: mqtt.publish
    data:
      topic: HomeAssistant/Studio/Fan/Status
      payload: '0'
  mode: single

Here’s the Generic Thermostat entry I placed in my configuration. yaml file…

#Generic Thermostat
climate:
  - platform: generic_thermostat
    name: StudioFan
    heater: switch.fanrelay
    target_sensor: sensor.inside_temp_temperature
    min_temp: 20
    max_temp: 24
    ac_mode: true
    target_temp: 22
    initial_hvac_mode: "cool"

I hope that someone has setup the functionality I am seeking? Appreciate any help :grinning:

Actually the major function of generic thermostat is to ensure that the target temperature is maintained in according to the modes so it is not bypassing the automation.

You can initiate mqtt post when the fan is on by creating an automation which is triggered when the switch.fanrelay is on or off. The automation should look like this.

alias: Fan Status
description: ''
mode: single
trigger:
  - platform: state
    entity_id: switch.fanrelay
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: switch.fanrelay
            state: 'on'
        sequence:
          - service: mqtt.publish
            data:
              topic: HomeAssistant/Studio/Fan/Status
              payload: '1'
      - conditions:
          - condition: state
            entity_id: switch.fanrelay
            state: ''
            for: 'off'
        sequence:
          - service: mqtt.publish
            data:
              topic: HomeAssistant/Studio/Fan/Status
              payload: '0'
    default: []

Thank you for the help and advice, makes perfectly good sense. Embarrassed I hadn’t thought of it myself.

I attempted to use your code and it gave me the error: Message malformed: offset off should be format ‘HH:MM’, ‘HH:MM:SS’ or ‘HH:MM:SS.F’ for dictionary value @ data[‘action’][0][‘choose’][1][‘conditions’][0][‘for’]

So I tried entering it another way (see code below)… and I received this error: Message malformed: extra keys not allowed @ data[‘default’]

alias: Fan Status
description: ''
mode: single
trigger:
  - platform: state
    entity_id: switch.fanrelay
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: switch.fanrelay
            state: 'on'
        sequence:
          - service: mqtt.publish
            data:
              topic: HomeAssistant/Studio/Fan/Status
              payload: '1'
      - conditions:
          - condition: state
            entity_id: switch.fanrelay
            state: 'off'
        sequence:
          - service: mqtt.publish
            data:
              topic: HomeAssistant/Studio/Fan/Status
              payload: '0'
  default: []

Any ideas?

Please try this code.

alias: Fan Status
description: ''
mode: single
trigger:
  - platform: state
    entity_id: switch.fanrelay
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: switch.fanrelay
            state: 'on'
        sequence:
          - service: mqtt.publish
            data:
              topic: HomeAssistant/Studio/Fan/Status
              payload: '1'
      - conditions:
          - condition: state
            entity_id: switch.fanrelay
            state: 'off'
        sequence:
          - service: mqtt.publish
            data:
              topic: HomeAssistant/Studio/Fan/Status
              payload: '0'
    default: []
1 Like

Implemented the revised code and all appears to be working. You’ll be happy to know your code also solved another problem I’ve been wanting to solve for some time.

Really appreciate the help. Thank you :+1: