Automation plug wifi

Hey there,

i have created an automation with one plug wifi tplink.
but it didn’t work. I think i have done it well. I do not undertand

- id: '1596555741515'
  alias: Imprimante 3D
  description: ''
  trigger:
  - below: '0.50'
    entity_id: sensor.plug_salon_amps
    for: '600'
    platform: numeric_state
  condition:
  - condition: device
    device_id: xxxxxxxxxxxxxxxxxxxxxx
    domain: device_tracker
    entity_id: device_tracker.pixel_4
    type: is_not_home
  action:
  - device_id: xxxxxxxxxxxxxxxxxxxxxx
    domain: switch
    entity_id: switch.plug_salon
    type: turn_off
  - data:
      message: Impression terminée, Arrêt du plug imprimante 3D.
    service: notify.telegram_sebastien
  mode: single

I try to turn off the plug, when i’m not home ( smartphone not at home ).
But it’s a plug for printer3D.
Conditions:
if power < 0.50A
and smartphone not home ( i’m out )
for xxx second. Plug turn off.

But doesn’t work :frowning:

Does the automation work when you teigger ir manually (this will skip all triggers and conditions and go straight ro the action part)?

You need to remove the quotes around the numbers 0.50 and 600, otherwise it will be a string and you can’t compare sterngs to numbers.

If i use the button for execute, it’s work and send me the telegram notification.
i have delete the ‘’

600 it’s 600 second ?

For trying,
i have deleted the smartphone condition. and modificated the 0.50 and 600 deleted the ‘’ . Then i have deleted 600 and write 10 ( second ).
then i have restart Hass, and shutdown worked.

Now, i have put the plug on for a second test, without any change. But the automation do not shutdown it again why ?

Try with this simple one first :

- id: '1596555741515'
  alias: Imprimante 3D
  description: ''
  trigger:
  - below: '0.50'
    entity_id: sensor.plug_salon_amps
    for: 00:01:00
    platform: numeric_state
  action:
  - service: switch.turn_off
    data:
      entity_id: switch.plug_salon
  mode: single

That’s actually not true. It will work as is with the quotes. The trigger code will convert the below value to a float and the for value to an int.

Of course the quotes are not required here and it makes more sense to enter the values as numbers instead of strings, so I would agree the quotes should be removed, but not because they have to be.

1 Like

The problem may be that the sensor is not changing. It has to change to a value that is below 0.5, and then stay below 0.5 for 600 seconds (i.e., 10 minutes.) Once it does that the condition will be checked.

So, if it goes below 0.5, and stays below 0.5 for 10 minutes, but you’re still home, then it won’t trigger again just because you leave home.

I’d suggest:

- id: '1596555741515'
  alias: Imprimante 3D
  description: ''
  trigger:
  - below: 0.50
    entity_id: sensor.plug_salon_amps
    for:
      minutes: 10
    platform: numeric_state
  - platform: state
    entity_id: device_tracker.pixel_4
    from: 'home'
  condition:
  - condition: device
    device_id: xxxxxxxxxxxxxxxxxxxxxx
    domain: device_tracker
    entity_id: device_tracker.pixel_4
    type: is_not_home
  - condition: numeric_state
    entity_id: sensor.plug_salon_amps
    below: 0.5
    for:
      minutes: 10
  action:
  - device_id: xxxxxxxxxxxxxxxxxxxxxx
    domain: switch
    entity_id: switch.plug_salon
    type: turn_off
  - data:
      message: Impression terminée, Arrêt du plug imprimante 3D.
    service: notify.telegram_sebastien
  mode: single

Aww, if i understand.

The trigger does not work as a loop ?
I have to put a condition, if i want to restart the trigger ?

No, that’s not it at all.

A trigger watches for some event to occur. In this case it was watching for the sensor to change to a value below 0.5 and then stay below 0.5 (i.e., either not change again at all, or if it did change, change to a value that is still below 0.5) for 10 minutes. Once it did that the trigger would “fire.” It will not fire again until the value changes to 0.5 or above and then back to below 0.5 for 10 minutes.

So, as I explained, if that happened when you were home, the automation would not run. So what I suggested was to add another trigger that watches for you to leave home. Then I added another condition that checks if the sensor value has been below 0.5 for at least 10 minutes.

The idea is, the automation watches for both events, and then whenever either occurs (sensor below 0.5 for 10 minutes, or you leave home), it checks to make sure that both conditions are true (sensor below 0.5 for at least 10 minutes and you’re not home), and if so, the automation runs.

1 Like

Ok, thank for the explanation.

I would try to be better with next automation :).

Thanks a lot for it.

Sorry for my english :wink:

1 Like

Didn’t know that, thanks for the information!

Another question for complete my reflexion.
Is the smartphone tracking the better way for detect if i’m at home or not ?

thanks.

What is “better” is completely dependent on your own particular situation. There are many, many ways to do that. There are hundreds, if not thousands, of topics on this forum regarding that one question. :smile:

Haha,

i would like to say an efficient and good precision :).
i have to learn so much to understand this powerfull tool :slight_smile:

@pnbruckner
Hey there,
i haven’t restart yesterday my Hass. But it’s looks like there is a problem with the code.
I can’t restart Hass.

Invalid config for [automation]: [for] is an invalid option for [automation]. Check: automation->condition->1->for. (See /config/configuration.yaml, line 21).

It’s looks like condition : for does not exist

You’ll have to post the code if you would like us to see what might be wrong with it.

That was exactely your code.
I have deleted in the condition :

    for:
      minutes: 10

and it works.
But when i’m not at home, that doen’t work
If i use a button to start the plug out of home that condition doesn’t works.

You have to post the entire automation, not just a snippet. There’s no way to know what is causing that error unless we can see the whole automation.

- id: '1596555741515'
  alias: Imprimante 3D
  description: ''
  trigger:
  - below: 0.50
    entity_id: sensor.plug_salon_amps
    for:
      minutes: 10
    platform: numeric_state
  - platform: state
    entity_id: device_tracker.pixel_4
    from: 'home'
  condition:
  - condition: device
    device_id: xxxxxxxxxxxxxxxxxxxxxx
    domain: device_tracker
    entity_id: device_tracker.pixel_4
    type: is_not_home
  - condition: numeric_state
    entity_id: sensor.plug_salon_amps
    below: 0.5
    for:
      minutes: 10
  action:
  - device_id: xxxxxxxxxxxxxxxxxxxxxx
    domain: switch
    entity_id: switch.plug_salon
    type: turn_off
  - data:
      message: Impression terminée, Arrêt du plug imprimante 3D.
    service: notify.telegram_sebastien
  mode: single

that’s the code you suggested to me.
in condition : for minutes doesn’t work.
Needed to delete this command

Ah, ok, now I see. I’ve got too many conversations going on at the same time!

I forgot the numeric_state condition does not accept for.

Without going back and re-reading everything, I can say a common way to deal with this is to create a template binary sensor that is on when that entity’s numeric state is below 0.5, then use the binary sensor in the trigger and condition instead.