How to run automation whenever a variable is a certain value

Im trying to run an automation based on a value of energy being below a certain negative value.

What I want to do is whenever energy above -1KW (for clarification anything larger than -1kw means -1,1, -2, etc) run a notification, but the trigger doesnt seem to ever run.

Any ideas? Thanks!


Please show your actual automation.
The one you show doesn’t have any actions, so obviously nothing will happen.

-2 is not larger than -1. And, -1 is not larger than -1 either.

This is the automation.
It should still run when the condition is met (does nothing, but records last time it run).

Ive added the command to turn on a smart plug, which works ok when manually triggered.

Here’s a screenshot:

I trust ‘below -1’ is correct as -2 is numerically smaller than -1, but for some reason it never runs.

Thanks

Numerically true.

In the future please post properly formatted code instead of images.

The trigger will not fire unless the referenced entity crosses the threshold you’ve specified. Has it done that?

If you created the automation while the value was already below -1, the automation won’t fire until the value raises above -1 and then crosses below -1.

2 Likes

Gosh it took a long time to work out what you are doing here!

You are setting this up in the UI.

Your trigger is probably OK. You even say that it is recording the last time that it ran, so I guess the trigger works.

So if we go with ‘below’ and ‘-3’ is indeed below ‘-1’

So the issue is possibly with the action.
Normally we use entities, and service calls to turn plugs and switches on. You appear to have gone for the ‘device’ option, which is messier and must not be manually edited as this can break it.

Two actions on the same switch (smart plug) in UI (taken from edit YAML mode)

alias: New Automation
description: Test
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.octopus_agile_prices
    attribute: import_next
    below: 10
condition: []
action:
  - type: turn_on
    device_id: b4efebd27f11f68763c1ed300c6e5826
    entity_id: a871bcb8e2446b0c77b8cba580ce4aa3
    domain: switch
mode: single

as a device - turn on, and now as a switch:turn on an entity

alias: New Automation
description: Test
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.octopus_agile_prices
    attribute: import_next
    below: 10
condition: []
action:
  - service: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: switch.bedroom_light
mode: single

Same action, just easier to read, and you can edit the YAML

Try perhaps deleting the action you have, and replacing it with a new one, using ‘switch’ and ‘on’ and the entity?