Plunge pricing automation

I’ve written this automation to turn on some appliance when Octopus Agile prices drop below 0:

alias: Plunge pricing turn on high loads
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.octopus_energy_electricity_xxxx_xxxx_current_rate
    below: 0
action:
  - service: switch.turn_on
    target:
      device_id:
        - e57a05ea1bde2df7539a8a02344c044e
        - 4778d134938e4987a17ad92e62c45429
        - 7195e0682d82a452fbbac3da66def715
    data: {}
mode: single

Works fine. The issue I’m having is how to turn off the appliances when prices go back above 0. I could just write an automation identical to the one above, but changing “below” to “above” and “on” to “off”. This would work to turn off the appliances, but then it would keep on turning them off whenever they were turned on if the price was above 0. So I need some sort of condition to say “while” prices are below zero, “do this” but can’t find the code that will do this.

Any ideas appreciated.

No, it will only trigger when it goes above 0 (or below) as in it was below 0 and then it went above (it has to cross the threshold).

1 Like
alias: Plunge pricing turn on or off high loads
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.octopus_energy_electricity_xxxx_xxxx_current_rate
    below: 0
    above: 0
action:
  - service: "switch.turn_{{ iif(trigger.to_state.state | int(1) < 0, 'on', 'off') }}" 
    target:
      device_id:
        - e57a05ea1bde2df7539a8a02344c044e
        - 4778d134938e4987a17ad92e62c45429
        - 7195e0682d82a452fbbac3da66def715
    data: {}
mode: single
2 Likes

Thought I’d be better replying to this rather than starting a new thread…

I’ve done something broadly similar to this, although I created two scenes for “Plunge time” and “Plunge finished” to turn everything off/on. Code below…

alias: Octopus Plunge Pricing
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.octopus_energy_electricity_current_rate
    below: 0.01
condition: []
action:
  - service: scene.turn_on
    target:
      entity_id: scene.plunge_time
    metadata: {}
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.octopus_energy_electricity_current_rate
        above: 0
  - service: scene.turn_on
    target:
      entity_id: scene.plunge_time_finished
    metadata: {}
mode: single

The issue I have is, it only seems to trigger once. Plunge pricing is often in two or more separate half hour periods, and this only ever seems to trigger in the first one. I’ve checked the sensor values and all looks good. Am I missing something here?

Your Numeric State Trigger will trigger at the moment the sensor’s value decreases from above 0.01 to below 0.01. In other words, the moment it crosses the threshold of 0.01.

It won’t trigger again until the sensor’s value first increases above 0.01 then decreases below it.

Therefore after it triggers the first time, it won’t trigger again no matter much more the sensor’s value continues to decrease below 0.01. It’s the act of crossing the threshold value (0.01) that causes it to trigger.

1 Like

Thanks for the reply. Unfortunately I haven’t got the data from when it last happened, but the unit price sensor did indeed increase between the plunge periods. The intent of the automation was “when electricity is free or less than free, turn stuff on until it isn’t” which is why I was targeting less than 0.01 rather than negative rates only which I think is the OPs intention.

I have a sneaking suspicion that although the rates did increase between plunge periods, it might not have been by enough, I had mistakenly assumed the sensor unit was in pence like it appears on the Octopus rate card, but it’s pounds… I think if I change it to 0.000001 or something similarly low, that should achieve what I’m after.

Obviously now there won’t be a plunge period for the next 6 months to prove the theory :laughing: