Cannot get simple automation to work correctly

Hello all!

Can someone check my script? I added the config using the GUI and just cut and paste the YAML:
The switch comes on but does not turn off after hitting 70F

alias: Auto Space Heater
description: Turns plug on if temp below 68 and off if above 70
trigger:
  - platform: numeric_state
    entity_id: sensor.bedroom_temperature
    attribute: temperature
    above: '70.0'
  - platform: numeric_state
    entity_id: sensor.bedroom_temperature
    below: '68'
condition: []
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.bedroom_temperature
            attribute: temperature
            above: '70.0'
        sequence:
          - type: turn_off
            device_id: c7ba2df6df05aff532390d3248188352
            entity_id: switch.spare_outlet
            domain: switch
      - conditions:
          - condition: numeric_state
            entity_id: sensor.bedroom_temperature
            below: '68.0'
        sequence:
          - type: turn_on
            device_id: c7ba2df6df05aff532390d3248188352
            entity_id: switch.spare_outlet
            domain: switch
    default:
      - type: turn_off
        device_id: c7ba2df6df05aff532390d3248188352
        entity_id: switch.spare_outlet
        domain: switch
mode: restart

Look carefully at the two triggers. Aside from the fact they use different thresholds, what else is different about them?

  - platform: numeric_state
    entity_id: sensor.bedroom_temperature
    attribute: temperature <--------------- Why is this here?
    above: '70.0'
  - platform: numeric_state
    entity_id: sensor.bedroom_temperature
    below: '68'

It will work properly if you remove this line:

    attribute: temperature

EDIT

If you’re interested, here’s a more compact version of the automation:

alias: Auto Space Heater
description: Turns plug on if temp below 68 and off if above 70
trigger:
  - id: 'off'
    platform: numeric_state
    entity_id: sensor.bedroom_temperature
    above: '70.0'
  - id: 'on'
    platform: numeric_state
    entity_id: sensor.bedroom_temperature
    below: '68'
condition: []
action:
  - service: 'switch.turn_{{ trigger.id }}'
    target:
      entity_id: switch.spare_outlet
mode: restart

Better yet, I suggest you consider using the Generic Thermostat integration. It is perfect for this application (controlling a heater switch to maintain a desired temperature) and it allows you to use the Thermostat card.

2 Likes

Thank you so much for the reply. I was using the UI editor and I was a little confused on the flow of arguments. I am very new to programming and mostly just fumbling around until I figure it out. I really need to get some basic coding under my belt. :stuck_out_tongue:

So If I use the Generic Thermostat like you advised, how would I add that? Do I need code in the configuration.yaml and then make a blank card? I am getting errors when I try to cut and paste from the examples. I did change the entities name to match mine.

Post an example of what you have attempted to copy-paste into the configuration.yaml file.

climate:

  • platform: generic_thermostat
    name: Bedroom
    heater: switch.spare_outlet
    target_sensor: sensor.bedroom_temperature
    min_temp: 60
    max_temp: 80
    ac_mode: false
    cold_tolerance: 0.3
    hot_tolerance: 0
    min_cycle_duration:
    minutes: 5
    keep_alive:
    minutes: 3
    initial_hvac_mode: “off”
    precision: 0.2

Invalid config for [climate.generic_thermostat]: value must be one of [0.1, 0.5, 1] for dictionary value @ data[‘precision’]. Got 0.2. (See ?, line ?).

The error message explains the mistake.

The documentation for precision explains the only acceptable values are 0.1, 0.5, or 1. You used 0.2. Change it to one of the three acceptable values.

1 Like

Got her working. Thanks!

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.

1 Like