I'm new to Home Assistant. Need help with ESP yaml

I have an exhaust fan that I am controlling with climate bangbang component, I added a switch to turn the fan on manually but the climate component will turn it off anyway when the lower setpoint is reached. I added code to prevent this and want to add code to prevent the switch from turning the fan off if Climate is calling for it to be on but cant seem to work it out.


captive_portal:

output:
  - platform: gpio
    pin: GPIO12
    id: Exhaust_Fan
    inverted: False

switch:
  - platform: template
    id: Fan_Switch
    name: "Exhaust Fan"
    turn_on_action:
      - output.turn_on: Exhaust_Fan
    turn_off_action:
                lambda: |-
                  id(Exhaust_Fan_Tstat).action = cooling; {
                   output.turn_off: Exhaust_Fan;
                   }
sensor:      
  - platform: dallas_temp
    id: Temperature_sensor_1
    update_interval: 5s
    unit_of_measurement: "°F"
    accuracy_decimals: 1
#     on_value:
#          - if:
#              condition:
#                switch.is_off: Heater
#              then:
#                  if:
#                    condition:
#                      sensor.in_range:
#                        id: Temperature_sensor
#                        below: 71.0
#                    then:
#                    - switch.turn_on: Heater
#              else:
#                if:
#                  condition:
#                    sensor.in_range:
#                      id: Temperature_sensor
#                      above: 73.0
#                  then:
#                  - switch.turn_off: Heater
    filters:
      #- lambda: return x * (9.0/5.0) + 32.0;
      - sliding_window_moving_average:
          window_size: 15
          send_every: 1

one_wire:
  - platform: gpio
    pin: GPIO3
    id: OW_Network

climate:
  - platform: bang_bang
    id: Exhaust_Fan_Tstat
    name: "Exhaust Fan"
    sensor: Temperature_sensor_1
    default_target_temperature_low: 26.6 °C
    default_target_temperature_high: 29.5 °C

    cool_action:
      - output.turn_on: Exhaust_Fan
    idle_action:
      - if:
          condition:
            switch.is_off: Fan_Switch
          then:
            - output.turn_off: Exhaust_Fan
    visual:
      min_temperature: 0
      max_temperature: 40
      temperature_step:
        target_temperature: 0.5
        current_temperature: 0.1        

There are probably a bunch of different ways to address this...

Is the switch really necessary? The climate entity can already be set to "off" or "cool"...

If you think it is necessary, I would have the switch's turn_on/turn_off actions just change the temperature set point to extreme values. That way the state of the switch really doesn't matter for normal operation of the climate entity, but actions on the switch will have the desired effect.

It really depends on how you expect the device to work and the entities to appear in HA. So you will need to give us a better description for us to give you more specific instructions.

You probably need to define VERY clearly exactly the behavior you want. Mixing auto and manual is typically hard unless you are very clear.

As an example many thermostats have an override function (which overrides the set point, typically until the next scheduled change). Since it is well defined it is reasonably easy to implement the desired behavior.

If you want the manual override to just turn the fan on having it change the set point (as suggested above) could work.

I have a more complicated set up for my heated floor and hot water recirculation system. I have sensors that determine if someone is present. I aggregate them to determine away/here. I also have different set points for away/here based on time of day. I have a place where I set the different temperatures for each time period and state. The automations then update the current control settings based on here/away changes (and the away/here settings based on time).

It is complicated, but that is because the behavior I want is not simple.

Thanks for the responses but I got it.

output:
  - platform: gpio
    pin: GPIO12
    id: Exhaust_Fan
    inverted: False

switch:
  - platform: template
    id: Fan_Switch
    name: "Exhaust Fan"
    optimistic: true
    turn_on_action:
      - climate.control:
          id: Exhaust_Fan_Tstat
          mode: "OFF"
      - delay:
          milliseconds: '10'
      - output.turn_on: Exhaust_Fan
    turn_off_action:
      - output.turn_off: Exhaust_Fan
      - delay:
          milliseconds: '10'
      - climate.control:
          id: Exhaust_Fan_Tstat
          mode: "COOL"
climate:
  - platform: bang_bang
    id: Exhaust_Fan_Tstat
    name: "Exhaust Fan"
    sensor: Temperature_sensor_1
    default_target_temperature_low: 26.6 °C
    default_target_temperature_high: 29.5 °C

    cool_action:
      - output.turn_on: Exhaust_Fan
    idle_action:
      - output.turn_off: Exhaust_Fan
    visual:
      min_temperature: 0
      max_temperature: 40
      temperature_step:
        target_temperature: 0.5
        current_temperature: 0.1
        
sensor:      
  - platform: dallas_temp
    id: Temperature_sensor_1
    update_interval: 5s
    unit_of_measurement: "°F"
    accuracy_decimals: 1
#     on_value:
#          - if:
#              condition:
#                switch.is_off: Heater
#              then:
#                  if:
#                    condition:
#                      sensor.in_range:
#                        id: Temperature_sensor
#                        below: 71.0
#                    then:
#                    - switch.turn_on: Heater
#              else:
#                if:
#                  condition:
#                    sensor.in_range:
#                      id: Temperature_sensor
#                      above: 73.0
#                  then:
#                  - switch.turn_off: Heater
    filters:
      #- lambda: return x * (9.0/5.0) + 32.0;
      - sliding_window_moving_average:
          window_size: 15
          send_every: 1

one_wire:
  - platform: gpio
    pin: GPIO3
    id: OW_Network

Based on what you implemented, it sounds like your requirement was: allow manual override of control to force fan on, return back to auto control when manual override is turned off

Yes like an industrial HOA, I'm not satisfied with this though due to the unnecessary switching during delay. I am an industrial programmer and would never do this with a PLC. I'm sure with a little more work I can find a way to check the state/status of the Tstat and do an If/Then or something similar.

If im assuming correctly that this similar to pretty much every other type of exhaust fan then it makes me even question the need for using one of the climate platforms since all it seems to be is just a fan that technically can't "heat" or "cool" and instead just moves ambient air from A to B which makes the whole reason for needing a GUI thermostat with selections for Heat/Cool options.

Instead, why not just use the actual Fan platform that would already come with a toggle switch and its just as easy to create min/max temp thresholds to automate its On/Off setting and then just add an additional template switch that will work as a "manual control" switch and when On, it would disable your automation based on min/max temp so that its not turning it off when you want it to be On and manually controlled???

This works great and eliminated the delay switching. Thanks again for everyone's positive input.

captive_portal:

output:
  - platform: gpio
    pin: GPIO12
    id: Exhaust_Fan
    inverted: False

switch:
  - platform: template
    id: Fan_Switch
    name: "Exhaust Fan"
    optimistic: true
    turn_on_action:
      - output.turn_on: Exhaust_Fan
    turn_off_action:
      - lambda: |-
          if (id(Exhaust_Fan_Tstat).action != CLIMATE_ACTION_COOLING) {
          id(Exhaust_Fan).turn_off();}
climate:
  - platform: bang_bang
    id: Exhaust_Fan_Tstat
    name: "Exhaust Fan"
    sensor: Temperature_sensor_1
    default_target_temperature_low: 26.6 °C
    default_target_temperature_high: 29.5 °C

    cool_action:
      - output.turn_on: Exhaust_Fan
    idle_action:
      - if:
          condition:
            switch.is_off: Fan_Switch
          then:
            - output.turn_off: Exhaust_Fan
    visual:
      min_temperature: 0
      max_temperature: 40
      temperature_step:
        target_temperature: 0.5
        current_temperature: 0.1
        
sensor:      
  - platform: dallas_temp
    id: Temperature_sensor_1
    update_interval: 5s
    unit_of_measurement: "°F"
    accuracy_decimals: 1
#     on_value:
#          - if:
#              condition:
#                switch.is_off: Heater
#              then:
#                  if:
#                    condition:
#                      sensor.in_range:
#                        id: Temperature_sensor
#                        below: 71.0
#                    then:
#                    - switch.turn_on: Heater
#              else:
#                if:
#                  condition:
#                    sensor.in_range:
#                      id: Temperature_sensor
#                      above: 73.0
#                  then:
#                  - switch.turn_off: Heater
    filters:
      #- lambda: return x * (9.0/5.0) + 32.0;
      - sliding_window_moving_average:
          window_size: 15
          send_every: 1

one_wire:
  - platform: gpio
    pin: GPIO3
    id: OW_Network

Does anyone here have experience controlling a heating device with a triac including circuitry to prevent runaway in the event the triac failed closed?

Its often times easier and just as dependable if you instead set the existing ā€œheating deviceā€ temperature settings somewhere just above what you actually want for your maximum temp shutdown like 73 degrees for example and then simply plug it into a smart relay that will control the On/Off while another esphome type device with temperature sensor/s monitors the room temperature and can very easily and reliably send commands to the relay that will toggle it On/Off. If for something randomly happens to your Esphome/temperature device and cant send those On/Off commands to hour heating device then it’s no big deal because you always keep it set just above your maximum desired temperature and that is where it will shutdown in an emergency.

It would also kinda help to know exactly what type of device specifically that your inquiring about so that people dont have to speculate too.