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
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.
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.
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.
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 ?).
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.