Hello,
I searched in the forum but I was not able to find an answer to my question/problem.
I have an automation with a template trigger, that does some calculations and then evaluate a condition to fire the automation.
I would like to use the result of the calculation (stored in a variable) in the action.
If I manually set the value of the trigger variable, this is passed and made available in the action (I get a Telegram notification with that value).
Issue 1: {‘object Object’: None} Usually indicates that you didn’t properly enclose a template in quotes or use a multi-line quote designator. In this case it was the template for threshold:
Issue 2: Variables defined in Jinja have local scope, they are not available outside the block they are defined in.
trigger:
- platform: template
value_template: >-
[...]
{% set test = 5 %} {# test has value here #}
variables:
threshold: "{{test}} {# test is undefined/none here #}"
action:
- service: notify.xxx
data:
title: "xxx"
message: >-
Value is {{threshold}} {# Since test is none, threshold is none #}
If you give a more detailed explanation of what you are trying to do we can suggest options for you.
I see… I learned variables have local validity (and also some limitations when loops are involved - I found the workaround of “namespace” to extend the scope to inner loops) but I thought/hoped that a variable defined in the trigger block was available through it all, so also for the “variables”.
What I developed is an automation to get a Telegram notification when the external temperature (from a sensor) approaches (within a threshold, that I define inside a variable) the average temperature of rooms with the window open (which I calculate and store in another variable to be able to perform the comparison with the external temp, considering the threshold, and fire the automation).
The calculations, the trigger and the action work.
What I’d now like to do is to enrich the notification message with the external temperature (not a problem - easy to do) but also the average internal temperature (which I calculate) and the threshold (I statically set) values, both stored inside variables.
Does this make sense?
I thought the function of this version of “trigger variables” was to make values available outside the trigger block, but if they can’t be dynamically set I can’t see its utility.
That’s not a bad idea. A bit more dispersive as not everything is in a single place but probably the easiest and only (for now) way to get this working the way I’d like.
Thanks for the suggestion but especially for explaining this can’t work in the way I expected.