trigger -
actions:
choose
option 1: if true set a = "1"
choose
option 1: if true set a = a ~ " 2"
choose
option 1: if true set a = a ~ " 3"
notify
data:
message: "{{ a }}"
You are right, but I don’t know how to make the “set” thing into automation I mean… There is no template action where to have only “set variable” as action, then, I don’t know if the variable will keep value between actions, till the last action which will be notify…
Maybe with a “choose” action where I can add a secondary condition which will only have this “set”… I will try now
Oh wait… With this aproach, I don’t even need variables…
I can use something similar of what you told me.
In the last action which is the notifying action, I can write that if/endif thing…knowing the result of all the “choose” actions, right?
Well, you should of course replace the option == true clauses with whatever condition you have. If I just use true in the template helper, the string comes out so it should be doable. There’s no need for, or relation to, a choose with this template.
I thought that option1, 2, 3… it is a global “variable”… Because home assistant does know if all the “choose” actions are true or false and thinking of this, I thought that maybe it is stored somewhere… I think I will stick to the helper
I didn’t try, but I’m kindof surprised that if you declare a variable in a script, that setting it in a choose won’t hold. Kind of defeats the purpose a bit.
You could possibly make a nicer formatted multiline jinja template as well, if that is your concern. The input helper will work if you have only one “single” automation using it, but it feels like overkill. But hey, you’ll have a history of messages
With the helper, yes, for only one automation, of course. And it will work like tom_l said, concatening the messages… And after the notification, the helper will be empty again, waiting to be filled
As usability of variables with “choose”, i’ve created a “choose” condition for the primary purpose, and the second condition only to declare the variable… but yeah… the bad part is that the variables are not keepling the value between actions…
If first condition will be true, the second will be automatically true and set the variable, but as I thought already (but I tested as well), the variable does not keep between actions
There’s a difference between script variables and Jinja2 variables and their scope. A script variable’s scope can be global for the script whereas a Jinja variable’s scope is always limited to the YAML option in which it’s defined.
The Jinja2 variable named option1 is referenced in the message option but it’s undefined; it’s not defined anywhere in the message option. In addition, if anyone is assuming it is somehow related to the choose statement, it’s not.
Instead of posting your requirements in pseudo-code, describe the application you wish to construct.
I almost finished, but I only need one more information. How the hell I can store a “new line” in the input_text helper? I mean… It is only storing strings, no new line? I tried with “\n” but nothing…
If you explain exactly what your application is (notably the output you expect because your first post doesn’t mention the need to include a new line but your most recent post does) then I can help you achieve your goal.
I am trying to make an automation with a notification for the sensors which could have a malfunction … and I use “choose”, in order to know which sensor have a problem, then I set the information into the input_select, and… at the end, I will have the notification
If that’s your goal then you’ve chosen a very peculiar way of achieving it. There may be a simpler solution, implemented entirely with a template, but it depends on the details of your sensors. What is the criteria you are using to determine if a sensor has a problem?
For example, the following template lists the names of all sensors whose state is either unavailable or unknown.
{% set time = (as_timestamp(now()) - as_timestamp(states.sensor.broadlink_bedroom_humidity.last_changed)) | int %} {% if time > 14400 %}true{% endif %}
If in 4 hours the humidity won’t change, I am more than 95% that it is not working