Hi
I got stuck with automation and can’t find out how to move on.
My configuration is simple. I have a ESPHome device with temperature sensor and relay with heater. And I want HA turn off or turn on heating when temperature goes above/below threshold. Logically is simple
ESPHome device sends every minute data to HA
[10:39:25][D][api.connection:604]: Client 'Home Assistant 2021.3.4 (192.168.88.2)' connected successfully!
[10:39:25][D][api.connection:604]: Client 'Home Assistant 2021.3.4 (192.168.88.2)' connected successfully!
[10:40:03][D][dht:048]: Got Temperature=20.9°C Humidity=93.0%
[10:40:03][D][sensor:092]: 'Snail House Temperature': Sending state 20.90000 °C with 1 decimals of accuracy
[10:40:03][D][sensor:092]: 'Snail House Humidity': Sending state 93.00000 % with 1 decimals of accuracy
[10:41:03][D][dht:048]: Got Temperature=20.7°C Humidity=93.0%
I know that every minute is too often but it is for debug purposes. And HA sees sensor and relay, I can turn on/off relay and can read temperature from dashboard.
And this is my automation:
- id: '1616958574282'
alias: Snail House
description: Automation for snail house heater
trigger:
- platform: numeric_state
entity_id: sensor.snail_house_temperature
value_template: '{{ state.attribute.temperature }}'
attribute: attribute_name
for: 0:10:00
above: '20'
- platform: numeric_state
entity_id: sensor.snail_house_temperature
attribute: friendly_name
for: 0:10:00
below: '19'
value_template: '{{ state.attribute.temperature }}'
condition: []
action:
- choose:
- conditions:
- condition: numeric_state
entity_id: sensor.snail_house_temperature
below: '19'
value_template: '{{ state.attribute.temperature }}'
sequence:
- service: script.snail_house_turn_on_heater_script
- service: notify.persistent_notification
data:
data:
message: message - heating is ON
title: title - heating is ON
- conditions:
- condition: numeric_state
entity_id: sensor.snail_house_temperature
above: '20'
"homeassistant/config-ha/automations.yaml" 51L, 1535C 9,13 Top
for: 0:10:00
action:
- choose:
- conditions:
- condition: numeric_state
entity_id: sensor.snail_house_temperature
below: '19'
value_template: '{{ state.attribute.temperature }}'
sequence:
- service: script.snail_house_turn_on_heater_script
- service: notify.persistent_notification
data:
data:
message: message - heating is ON
title: title - heating is ON
- conditions:
- condition: numeric_state
entity_id: sensor.snail_house_temperature
above: '20'
value_template: '{{ state.attribute.temperature }}'
sequence:
- service: script.snail_house_turn_off_heater
- service: notify.persistent_notification
data:
data:
message: message - heating is off
title: title - heating is OFF
default:
- service: notify.persistent_notification
data:
data:
message: Temperature is ok
title: TEMP IS OK
mode: queued
max: 10
again - persistent notifications are just for debug purposes.
and this doesn’t work. I would appreciate it if anyone would point/advise what I am doing wrong
Then it was as I thought. The attribute lines are wrong. They should not be there.
You only have state in the entity to care about.
But I agree with thermostat.
Logger: homeassistant.components.homeassistant.triggers.numeric_state
Source: components/homeassistant/triggers/numeric_state.py:161
Integration: Home Assistant Core Integration (documentation, issues)
First occurred: March 29, 2021, 9:21:25 PM (158 occurrences)
Last logged: 11:49:03 AM
Error in 'Snail House' trigger: In 'numeric_state' condition: entity sensor.snail_house_temperature state '°C' cannot be processed as a number
Error in 'Snail House' trigger: In 'numeric_state' condition: entity sensor.snail_house_temperature state 'Snail House Temperature' cannot be processed as a number
Error in 'Snail House' trigger: In 'numeric_state' condition: attribute 'attribute_name' (of entity sensor.snail_house_temperature) does not exist
Error in 'Snail House' trigger: In 'numeric_state' condition: entity sensor.snail_house_temperature state '' cannot be processed as a number
Error in 'Snail House' trigger: In 'numeric_state' condition: template error: UndefinedError: 'homeassistant.core.State object' has no attribute 'attribute'
currently automation looks like
- id: '1616958574282'
alias: Snail House
description: Automation for snail house heater
trigger:
- platform: numeric_state
entity_id: sensor.snail_house_temperature
for: 0:01:00
above: '20'
- platform: numeric_state
entity_id: sensor.snail_house_temperature
for: 0:01:00
below: '19'
condition: []
action:
- choose:
- conditions:
- condition: numeric_state
entity_id: sensor.snail_house_temperature
below: '19'
sequence:
- service: script.snail_house_turn_on_heater_script
- service: notify.persistent_notification
data:
data:
message: message - heating is ON
title: title - heating is ON
- conditions:
- condition: numeric_state
entity_id: sensor.snail_house_temperature
above: '20'
sequence:
- service: script.snail_house_turn_off_heater
- service: notify.persistent_notification
data:
data:
message: message - heating is off
title: title - heating is OFF
default:
- service: notify.persistent_notification
data:
data:
message: Temperature is ok
title: TEMP IS OK
mode: queued
max: 10
I will try to use thermostat later, first I’d like to make this approach work to learn how to not make mistakes in a future
@sheminasalam, may I ask you to explain me one confusing thing?
my ESP device sends data every 10 minutes. So for 9 hours I’d expect to have 9(hours)*6(message per hour) = 54 message. However in my notification area I have only 17, They are coming 2-3 per hour. And I see in ESPHome logs that messages are being sent quite a lot. What could be a reason?