Hi I need to pass to script trigger.to_state
and trigger.from_state
for be able to read it in the script. Currently, I am trying many variations, but none of them work. last of my code is:
alias: Temperature Changed
description: ""
triggers:
- trigger: state
entity_id:
- climate.c686b3d1
- climate.c67df6bd
- climate.c686b579
- climate.c686b3b8
attribute: current_temperature
conditions: []
actions:
- action: script.temperature_notification_2
metadata: {}
data:
to_ac_state: "{{ trigger.to_state }} "
from_ac_state: "{{ trigger.from_state }}"
# I have default value for the levels and required: false,
# but I can't run the script without the params,
# if someone know how resolve and this issue please help.
high_temp_level: 26
low_temp_level: 22
mode: parallel
and
alias: Gree Climat Temperature Notification
description: >-
Temperature Notification for Gree Climate devices. The entities can be passed
from automation as `trigger.to_state.entity_id` or
`trigger.from_state.entity_id`
sequence:
- variables:
# HERE: I can't read the state as object, what is wrong?
test_1: "{{ to_ac_state.state }}"
test_2: "{{ to_ac_state.friendly_name }}"
name: "{{ state_attr(to_ac_state,'friendly_name') }}"
temp: "{{ state_attr(to_ac_state,'current_temperature') }}"
from_temp: "{{ state_attr(from_ac_state,'current_temperature') }}"
- if:
- condition: template
value_template: >-
{% if temp > high_temp_level %} true
{% elif temp < low_temp_level %} true
{% elif from_temp > high_temp_level %} true
{% elif from_temp < low_temp_level %} true
{% else %} false
{% endif %}
then:
- variables:
temp_level: >-
{% if temp > high_temp_level %} High
{% elif temp < low_temp_level%} Low
{% else %}
{% endif %}
change_direction: >-
{% if from_temp < temp %} increased to
{% elif from_temp > temp %} decreased to
{% else %} is
{% endif %}
- data:
title: š”ļø {{ temp_level }} Temp.
message: >-
{{ name }}: Temperature {{ change_direction }} {{ temp }}Ā°C {{ from_temp }}
action: notify.evgen
fields:
to_ac_state:
selector:
object: {}
name: To AC State
description: Climat entity
required: true
from_ac_state:
selector:
object: {}
name: From AC State
description: Climat entity
required: true
high_temp_level:
selector:
number:
min: 1
max: 100
name: High temp level
description: abowe this value temp is high
default: 26
low_temp_level:
selector:
number:
min: 1
max: 100
name: Low temp level
description: below this value temp is low
default: 22
icon: mdi:air-conditioner
In trace the script ,I can see, I receive the data as
to_ac_state: >-
{'hvac_modes': [<HVACMode.AUTO: 'auto'>, <HVACMode.COOL: 'cool'>,
<HVACMode.DRY: 'dry'>, <HVACMode.FAN_ONLY: 'fan_only'>, <HVACMode.HEAT:
'heat'>, <HVACMode.OFF: 'off'>], 'min_temp': 8, 'max_temp': 30,
'target_temp_step': 1, 'fan_modes': ['auto', 'low', 'medium low', 'medium',
'medium high', 'high'], 'preset_modes': ['eco', 'away', 'boost', 'none',
'sleep'], 'swing_modes': ['off', 'vertical', 'horizontal', 'both'],
'current_temperature': 28, 'temperature': 26, 'fan_mode': 'low',
'preset_mode': 'none', 'swing_mode': 'off', 'friendly_name': 'Cabinet AC',
'supported_features':
<ClimateEntityFeature.TARGET_TEMPERATURE|FAN_MODE|PRESET_MODE|SWING_MODE|TURN_OFF|TURN_ON:
441>}
and results for first variables is:
test_1: ''
test_2: ''
name: null
temp: null
from_temp: null