My tasmotized wall plugs lose their connection to the MQTT broker on a regular basis.
So I tried to implement an automation to check if there are unavailable plugs and in case their binary_sensor.ping was on, fire a restart command.
This works:
Yes, but only in template conditions except in very limited circumstances which are always documented (one example is the for: parameter). Anywhere you can properly use a template, variables will work.
In your case here, it’s not working because the syntax of your template is incorrect. You are trying to use a template inside of a template instead of properly concatenating the entity_id string and variable.
Thank you very much. Works.
Would be great if that’d be written in the docs.
A pity I’m not educated enough to submit a PR to the docs.
(likewise: the shell_command docs don’t state that you have to restart HA for the entries to work; reloading the YAML isn’t enough).
The issue you were having was not with HA, it was with Jinja which is the “language” used in HA templates. While the HA documentation does have some helpful jinja hints and documents HA specific items, for basic jinja syntax you will need to refer to the jinja docs. Here’s a link to the operators section which explains the tilde (~) operator.
There is nothing to document. There is no reload service for shell_command. If there is no reload service for the integration in question, you must always restart HA for changes to take effect. You can check for (and run) a reload service in Dev Tools → Services. If there is no reload service, you must restart.
It may be that the docs are “correct”, just specifying HA related stuff.
For me (and I’d bet more than half of the HA user base) it’s difficult to dig up the information I need.
First stop is always the forums, but the search doesn’t always yield what I (think to) need.
Next stop ist HA docs. Maybe they are technically correct and thorough, but of limited use for non-programmers if the crucial hints are missing.
Take the shell_command as an example: While your reason “If there is no reload service, you must restart.” makes perfect sense, it does so naturally only to the 10000 (power-)users who are fluent in all things HA. It isn’t at all obvious to the rest of us. That’s why this exact sentence is needed within the docs (“Remember: …!”) for the average Joe.
Last stop is the search engine of your choice. I must admit that for me this yields better results than the forum search (the first pages are nearly completely links to the forums). The HA docs links I don’t follow anymore - normally I’ve been there already.
As for the use of Jinja2, JS/TS and even YAML: some things you pick up scanning the examples and -even better- other users githubs. But it’s too much to ask of an average user to really learn these languages.
I’ve got a basic hang of YAML (and like it) since it’s only a descriptive language with limited functionality. Jinja and JavaScript on the other hand are real programming languages I never used before and I’ve got neither the brains nor the time to dive into them.
I only need examples which I can adapt to my needs. That is by far the main reason to search the forums and docs.
I’m sure most of the users see it this way.
And there is another important thing: spending hours of trial and error due to unobtainable pieces of information reduces the WAF to zero and below.
Sorry, that had to get out. It’s by no means aginst you two!