I'm really struggling with building even a simple automation

I’m brand new to Home Assistant. However I have over a decade working with universal Devices home automation system. Yet after watching may YouTube videos and reading lots of documentation I cant get even a simple test automation to run.

I’d appreciate all comments on what I’m missing in the following test example. I’ll show the settings in the UI and then the yaml code for it.

For this test automation I want HA to see when the power plug is off (not has been turned off but IS off, wait 10 seconds and turn it on.

Thanks to everyone in advance

You will need a trigger as this is how the automation is “triggered”.

I would use state, on to off for 10 secs as the trigger. then action switch on. No need for condition.

Clair,

You don’t have a trigger (an activity from a device) you’re waiting on, but you want to check on the state of something (then act on it). So this test would be better suited to a Script.

On top of that, if you can avoid using Devices, you’ll be better off using Entities in the long run (makes reviewing the YAML much easier, when it’s necessary). That is, instead of selecting a Device that is a switch or a light, select a Switch or a Light entity to include in your automations and such. (Entities are components of installed Devices)

Using a script, you can start with test for the state of your plug, then take appropriate action. You’d run the script manually. In the example you pose, you’d start with a new script, and add an IF/THEN Building Block. Scripts could be run from an automation, but we’re not at that stage just yet.

As @Arh said you need a trigger to trigger an automation. Additionally you should be using an entity of the device rather than the device. I don’t think devices have states like ‘on’ or ‘off’ but a plug type device will have a switch entity for controlling the power, usually something like switch.plug_on_off_power where ‘plug_on_off_power’ is the entity id of the switch entity of the device.

Edit: Did not see @bob.t response before answering

Hi Guys,

Thanks for the quick response. I’m trying to limit myself to learning what can and cant be done using the automation UI since I’m new to this. I want to build a good foundation before I expand into direct yaml, scripts etc… baby steps to build that foundation.

The feeling I got from the documentation was that triggers watch for changes and any trigger in an automation can start things rolling. I also got the feeling that the “And if” section handled conditions but not changes to a condition. Also in the AND IF section all entries in there had to be true not just ANY of the entries had to be true.

So It seems from your comments/help that the UI cant be triggered by a current state being true or not, am I understanding that correctly?

Again, baby steps :slight_smile:

As the posts above mention, automations in Home Assistant require a trigger (note how the Conditions/“And If” block is designated optional and the Trigger/“When” block is not).

Correct, without a trigger an automation never does anything.

Mostly correct. Conditions check against the current state of the system.

The basic logic is that all conditions combine using AND logic, but there are “building block” conditions you can use when OR or NOT logic is needed.

Generally, automations are triggered based on event-based monitoring. This is more efficient than continuous polling.

There can be rare cases when polling is necessary, and for that you can use a Time Pattern trigger to, essentially, set a polling rate. However, doing so really isn’t necessary for the vast majority of cases, once you learn how to properly use the other available trigger types.

Right. Triggers react to changes in a state or condition.

Example: If your plug turns on or off, you might want that change of state (trigger) to send a notification to your phone. But if it’s on or off and doesn’t change, the automation won’t be triggered.

Again, this is just for my learning and understanding. The plug I’m using for my “education” supplies entities for different aspects of power. I noticed and it made sense that if I pull the plug from wall power whatever wattage, ampere etc was last shown in HA stays that way. Makes sense since no new vaales are coming in.

That being the case, in general, how would you approach triggering an automation when the voltage that the plug is reading from the wall goes away? Or the reverse of this how would you trigger when the power came back on as far as the plug was concerned so it could do some action to what’s connected to that plug?

Well that is not how it is supposed to work. When a device is not responding, its state/attributes should change to being unavailable. Exactly how long that takes though would be up to whomever wrote the integration that is interfacing against that particular device (though I am sure there are developer guidelines for that).