Hi there. Trying to create a single automation for something that seems to me actually quite straightforward - but apparently isn’t.
Below my automation. Gunnar is my robotic lawnmower. I wanted to see Gunnar’s status in GUI. Black if it’s idle in the dock, green when mowing, yellow when actually charging batteries. That’s simply done with floorplan, input_number.gunnar_lataa: 0: idle, 1: charging, 2: mowing. The Power (3.3W) is very strict, it’s 3.2-3.3W when mowing, and 3.3W-3.4W when idle. So I made the automation first without conditions, works quite nicely (Alhtough problem 2 occurs). However, that heiman smart plug reports its state like every 5 seconds, filling my logs with thousands of lines “sensor.heiman_smart_plug_1_power triggered automation gunnar_tila”… Then I thought of conditions: what if I trigger action only in case power reports matter - when crossing 3.3W or 4.0W. But I cannot get the conditions work with trigger.entity_id (error message “Problem 1” below the code). Any help here?
Here I could easily replace the entity_id with sensor.heiman_smart_plug_1_power and it will work. However I have another identical automation where I can not do that. Hence decided to ask this with shorter piece of code.
Anyway. Even if deleting conditions I have a float problem (error message “Problem 2” below). I tried to 1) remove the {% else %} -statement from the end (as it might be useless), then 2) changed all action return values from e.g. 1 to 1.0, and finally 3) changed action return values from 1 to “1.0 | float” (without quotes). No effect. Still the automation seems to work.
- id: Gunnar_tila
alias: Gunnarin tila
mode: queued
trigger:
platform: state
entity_id: sensor.heiman_smart_plug_1_power
condition:
condition: or
conditions:
- condition: numeric_state
entity_id: '{{ trigger.entity_id }}'
below: 3.3
- condition: numeric_state
entity_id: '{{ trigger.entity_id }}'
above: 3.3
- condition: numeric_state
entity_id: '{{ trigger.entity_id }}'
below: 4.0
- condition: numeric_state
entity_id: '{{ trigger.entity_id }}'
above: 4.0
action:
service: input_number.set_value
data_template:
entity_id: input_number.gunnar_lataa
value: >
{% if states('sensor.heiman_smart_plug_1_power') | float < 3.3 %}
2
{% elif states('sensor.heiman_smart_plug_1_power') | float > 4.0 %}
1
{% elif states('sensor.heiman_smart_plug_1_power') | float < 4.0 %}
{% if states('sensor.heiman_smart_plug_1_power') | float > 3.3 %}
0
{% endif %}
{% else %}
{{ states('input_number.gunnar_lataa') | float }}
{% endif %}
Problem 1:
Invalid config for [automation]: Entity ID {{ trigger.entity_id }} is an invalid entity ID for dictionary value @ data['condition'][0]['conditions'][0]['entity_id']. Got None. (See ?, line ?).
Problem 2:
Error while executing automation automation.gunnarin_tila: expected float for dictionary value @ data['value']
9:25:01 PM – (ERROR) Automation - message first occurred at 9:25:01 PM and shows up 2 times
Gunnarin tila: Error executing script. Invalid data for call_service at pos 1: expected float for dictionary value @ data['value']
9:25:01 PM – (ERROR) Automation - message first occurred at 9:25:01 PM and shows up 2 times
1 post - 1 participant