davel4wa
(Davel4wa)
September 25, 2022, 7:20pm
1
I have a ‘trigger template’ that works fine when defined within the configuration.yaml file. I thought to create a template sensor using the UI template sensor integration but that is not working. When I plug the template into the Developer Tools/Template tool, it reports ‘trigger’ is undefined.
- trigger:
- platform: time
at: '00:00:00'
- platform: state
entity_id: sensor.xyz
davel4wa
(Davel4wa)
September 27, 2022, 10:08pm
3
I did not include that part of the code as I did not feel it would be useful. Here it is:
- trigger:
- platform: time
at: '00:00:00'
- platform: state
entity_id: sensor.filtered_inside_temp
sensor:
- name: 'Temperature Daily Minimum'
unique_id: 'temperature_daily_minimum'
unit_of_measurement: '°F'
device_class: temperature
state: >
{% set t_new = states('sensor.filtered_inside_temp') | float(-99) %}
{{ [t_new, this.state | float(-99)] | min if trigger.platform != 'time' else t_new }}
Running HA 2022.7.5 on Docker
You can’t stick stuff like that in to the template editor - because that is not a template - that’s just plain YAML.
The template editor is for templates - like for ex:
{% set w = state_attr('weather.weatherflow','forecast') %}
{% set d1 = w[0] %}
{% set d2 = w[1] %}
{% set d3 = w[2] %}
{% set d4 = w[3] %}
{% set d5 = w[4] %}
{% set d6 = w[5] %}
{% if ((d1['precipitation'] < 1.5) or (d1['precipitation_probability'] < 50)) %}
{% set rc = "Today" %}
{% elif ((d2['precipitation'] < 1.5) or (d2['precipitation_probability'] < 50)) %}
{% set rc = "Tomorrow" %}
{% elif ((d3['precipitation'] < 1.5) or (d3['precipitation_probability'] < 50)) %}
{% set rc = d3['datetime']|as_timestamp|timestamp_custom("%A") %}
{% elif ((d4['precipitation'] < 1.5) or (d4['precipitation_probability'] < 50)) %}
{% set rc = d4['datetime']|as_timestamp|timestamp_custom("%A") %}
{% elif ((d5['precipitation'] < 1.5) or (d5['precipitation_probability'] < 50)) %}
{% set rc = d5['datetime']|as_timestamp|timestamp_custom("%A") %}
{% elif ((d6['precipitation'] < 1.5) or (d6['precipitation_probability'] < 50)) %}
{% set rc = d6['datetime']|as_timestamp|timestamp_custom("%A") %}
{% else %}
{% set rc = "----" %}
{% endif %}
{{ rc }}
Which is my template for checking what day would be best to do the washing.
But the full YAML:
sensor:
- unique_id: 797a6a5d-5b5f-419d-b6be-0bef855080cb
name: Activity Rain Check
state: >-
{% set w = state_attr('weather.weatherflow','forecast') %}
{% set d1 = w[0] %}
{% set d2 = w[1] %}
{% set d3 = w[2] %}
{% set d4 = w[3] %}
{% set d5 = w[4] %}
{% set d6 = w[5] %}
{% if ((d1['precipitation'] < 1.5) or (d1['precipitation_probability'] < 50)) %}
{% set rc = "Today" %}
{% elif ((d2['precipitation'] < 1.5) or (d2['precipitation_probability'] < 50)) %}
{% set rc = "Tomorrow" %}
{% elif ((d3['precipitation'] < 1.5) or (d3['precipitation_probability'] < 50)) %}
{% set rc = d3['datetime']|as_timestamp|timestamp_custom("%A") %}
{% elif ((d4['precipitation'] < 1.5) or (d4['precipitation_probability'] < 50)) %}
{% set rc = d4['datetime']|as_timestamp|timestamp_custom("%A") %}
{% elif ((d5['precipitation'] < 1.5) or (d5['precipitation_probability'] < 50)) %}
{% set rc = d5['datetime']|as_timestamp|timestamp_custom("%A") %}
{% elif ((d6['precipitation'] < 1.5) or (d6['precipitation_probability'] < 50)) %}
{% set rc = d6['datetime']|as_timestamp|timestamp_custom("%A") %}
{% else %}
{% set rc = "----" %}
{% endif %}
{{ rc }}
attributes:
precipitation: >-
{% set w = state_attr('weather.weatherflow','forecast') %}
{% set d1 = w[0] %}
{% set d2 = w[1] %}
{% set d3 = w[2] %}
{% set d4 = w[3] %}
{% set d5 = w[4] %}
{% set d6 = w[5] %}
{% if ((d1['precipitation'] < 1.5) or (d1['precipitation_probability'] < 50)) %}
{% set rc = d1['precipitation_probability'] ~ "%: " ~ d1['precipitation'] ~ "mm" %}
{% elif ((d2['precipitation'] < 1.5) or (d2['precipitation_probability'] < 50)) %}
{% set rc = d2['precipitation_probability'] ~ "%: " ~ d2['precipitation'] ~ "mm" %}
{% elif ((d3['precipitation'] < 1.5) or (d3['precipitation_probability'] < 50)) %}
{% set rc = d3['precipitation_probability'] ~ "%: " ~ d3['precipitation'] ~ "mm" %}
{% elif ((d4['precipitation'] < 1.5) or (d4['precipitation_probability'] < 50)) %}
{% set rc = d4['precipitation_probability'] ~ "%: " ~ d4['precipitation'] ~ "mm" %}
{% elif ((d5['precipitation'] < 1.5) or (d5['precipitation_probability'] < 50)) %}
{% set rc = d5['precipitation_probability'] ~ "%: " ~ d5['precipitation'] ~ "mm" %}
{% elif ((d6['precipitation'] < 1.5) or (d6['precipitation_probability'] < 50)) %}
{% set rc = d6['precipitation_probability'] ~ "%: " ~ d6['precipitation'] ~ "mm" %}
{% else %}
{% set rc = "----" %}
{% endif %}
{{ rc }}
icon: mdi:tshirt-crew-outline
cannot be pasted in the template editor, only the template part can.
davel4wa
(Davel4wa)
September 27, 2022, 10:43pm
5
Right but that doesn’t work either as the template contains the term ‘trigger’ which ‘does not compute’ either.
This exists currently as a defined template sensor in my config, which works just fine. It seems not everything on the template platform is supported.
yeah you need to do:
{% set trigger = whatever %}
trigger in automations and template sensors - only exists at the time that a trigger is fired.
in the template editor it doesn’t exist until you define it.