Stop and start a action in esphome from within home assistant ui

I would like to control a switch from switching an output in esphome but I keep coming up with errors

I have a esphome device with a sensor that measures the temperature and when in range will operate the switch, but I don’t require this all the time hence the reason to disable the switch when not needed. I do still want the temperature readings in HA so don’t want to disable the esphome device completely.

I’ve created a input_boolean in HA in attempt to turn the automation in esphome on and off.

sensor:
  - platform: max6675
    name: "Oven Temperature"
    cs_pin: 15
    filters:
      - sliding_window_moving_average:
          window_size: 25
          send_every: 20
      - throttle: 30s
    on_value_range:
      - above: 24.0
        then:
          - switch.turn_off: heater
      - below: 23.0
        then:
          - switch.turn_on: heater

switch:
  - platform: gpio
    pin: 32
    id: heater
    name: "Oven relay"
    on_turn_on:
      - delay: 40s
      - switch.turn_off: heater

binary_sensor:
  - platform: homeassistant
    name: oven_proofing_switch
    entity_id: "input_boolean.oven_proofing"

I’ve tried creating an if-condition in the on_value_range unit after more reading released it’s not supported. So just not sure where to go from here or whether I’m doing things totally wrong and there’s a better way.

How about just setting up a thermostat?

I did look into that but because of the time to respond to heat changes I decided to create something that I can tune to my liking.

Tried this today but still can’t get it to work how I want. Any ideas on where I’m going wrong:

switch:
  - platform: gpio
    pin: 32
    id: heater
    name: "Oven relay"
    on_turn_on:
      - delay: 40s
      - switch.turn_off: heater

sensor:
  - platform: max6675
    name: "Oven Temperature"
    cs_pin: 15
    id: oven_temp
    update_interval: 1s
    on_raw_value:
      then:
        - sensor.template.publish:
            id: oven_temperature_raw
            state: !lambda return x;
    filters:
      - sliding_window_moving_average:
          window_size: 25
          send_every: 20
      - throttle: 30s
    on_value:
      then:
        if:
          condition:
            lambda: 'return id(oven_proofing_switch).state;'
          then:
    on_value_range:
      - above: 23.5
        then:
          - switch.turn_off: heater
      - below: 23.0
        then:
          - switch.turn_on: heater
    internal: false

I was hoping the on_value condition would consider the state of the oven_proofing_switch which was ‘ON’ at the time and would carryout the on_value_range condition, but its wasn’t to be.

You should put your if condition just after your then: ^^^.

The general structure should look like this.

You can use a switch condition.

Then do the same for your below trigger.

Thanks again but you can’t put if/then conditions in the on_value_range as I understand it, hence why I tried it this way.

I’ll have a look at the switch condition options again.

Try more like this…Untested.

switch:
  - platform: gpio
    pin: 32
    id: heater
    name: "Oven relay"
    on_turn_on:
      - delay: 40s
      - switch.turn_off: heater

sensor:
  - platform: max6675
    name: "Oven Temperature"
    cs_pin: 15
    id: oven_temp
    update_interval: 1s
    on_raw_value:
      then:
        - sensor.template.publish:
            id: oven_temperature_raw
            state: !lambda return x;
    filters:
      - sliding_window_moving_average:
          window_size: 25
          send_every: 20
      - throttle: 30s
      
    on_value_range:
      - below: 800.1
        then:
          - if:
              condition:
                binary_sensor.is_on: esp_oven_proofing
              then:
                - switch.turn_off: heater



binary_sensor:
  - platform: homeassistant
    name: oven_proofing_switch
    id: esp_oven_proofing
    entity_id: "input_boolean.oven_proofing"

You can pretty much put any action after a ‘then’, including if actions and associated conditions. Note how I added id.

So if you want to start/stop or turn it on/off. The best way would be to add another switch but use a template switch.

switch: 
  - platform: template
    name: "value range switch"
    id: value

Then add the switch as a condition to your above: 24

on_value_range:
  - above: 24
    then:
      if:
        condition:
           - switch.is_on: value
        then: switch.turn_off: heater

The logic isnt exactly how you need it nut im ony cell phone and i think you get the point. The above/below automation can check to see if the template switch is on/off. Depending on on/off it will or wont toggle the heater switch