Hi there, I can’t seem to get any if/else condition working in the automations.yaml. All I’m trying to do is to switch a Fibaro Wall Plug on if it’s off and vice versa. Here is what I tried:
Are you sure you saw it like this? I don’t think “type” is a valid parameter for an action, it should be service instead, or in your case service_template. Anyway, why don’t you use the the “toggle” service? The toggle service does exactly that, turn off if it’s on and turn on if it’s off.
It’s that new-fangled Device Automation thing. It’s a great idea when used via the UI. However, when converted to text in an automation, it looks like the long way to get something done (compared to calling a service). I’m not very familiar with its syntax. In this case, maybe it doesn’t like the presence of template in type?
I guess I didn’t know where the output from the “device automations” GUI editor got stored. But it makes sense that it is just plugged into the default automations.yaml file like the regular editor does.
It seems that in trying to “make it easier” that new way of doing things is creating more “gotcha’s” and ends up making it harder.
And it not only makes it harder for new people when things don’t work correctly or “it’s not supported” but it also makes it harder for more experienced people try to help them when it doesn’t work because we have to go back and relearn everything/set up a test instance/etc to help them figure out if it’s their logic or the automation editor that isn’t working correctly …
I like helping people but the complications of setting up a test instance to try to decipher the intricacies of the GUI editors is of almost no interest to me. Especially when the “old school” way of writing it by hand isn’t that hard and the forums are overflowing with examples of how to do things that way.
I don’t use the automation editor either so first time for me seeing this too. The thought of stuff like “device_id:8d939318d6374dafa825c29dcb711978” littered throughout my code hurts my head.
My question is why does it need a device_ID, a domain, AND an entity_id ? Isn’t that rather redundant? I did play around with it for a bit to check it out and I think the deal is that only devices that show up in the integrations panel are available as a device trigger/condition/action. Looks like the options available for device trigger type are also automatically set. I get several trigger types for a multi-sensor but nothing to choose from for my Nest thermostat. None of the devices I have offer a device action so I couldn’t test that. I think OP manually typed his template in the type: parameter when only values provided by the automation editor should be there. Does his switch even offer a device action?
It does say in the device automations docs that they are only meant to be configured in the UI.
I’m assuming that it is a work in progress and that magically everything will just work and every piece of code given on the forums will be transformed into the new format, with us old diehards (not that I’ve been hand coding that long (but I’ve NEVER used this ‘more problems than solutions’ editor) ) coming round having been won over by the elegant simplicity of it all.
Come the revolution, we’ll be first up against the wall.
I’d just like one example of a new format reasonably complex automation (against a standard one, preferably with some explanation) so I could use it as a rosetta stone.
Sorry for the confusion all. I’m a long time SmartHome user but new to Home Assistant. The code example was indeed created with the automation tool. I added the if/else snippet from another forum post because I was assuming you could use it anywhere instead of static strings. But the whole topic seems to be way more complex.
You are right that a toggle makes more sense in my example, but I wanted to learn the scripting basics to use it for other stuff later.
Guess I’ll ditch the GUI and start using the documentation and an external editor.
The Device Automations editor is very useful, especially for new users. It stores the code it generates in configuration.yaml or automations.yaml using new keywords like device_id and domain. It would be quite difficult to create this format manually, meaning without using the Device Automations editor, primarily because of device_id (it’s cryptic). However, it was never meant to be created manually, this is just its representation in YAML.
I think it’s a good thing that it does store it as YAML (despite being a bit cryptic) because the alternative would be how Hubitat works. All its automations (rules) are created via a graphical editior. This editor is more sophisticated than either Automation Editor or Device Automation editor. However none of the rules it produces can be saved as, or shared as, a text file. That’s right, there’s no way to transform the graphical rules into text. So if you visit their forum, all questions about rules are presented as screenshots. If you see a rule you like, you have to create it from scratch using the screenshot as a reference; the author is unable to share it as text.
One of Home Assistant’s strengths is its ability to save and share automations as text. If it did not have this feature, I doubt the growth of its popularity would have been as rapid as it’s been.