BottlecapDave / HomeAssistant-OctopusEnergy

Unofficial Home Assistant integration for interacting with Octopus Energy
https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/
MIT License
541 stars 52 forks source link

Target rate sensor under a certain price per kWh #423

Closed djdarlo closed 2 months ago

djdarlo commented 9 months ago

Describe the feature

Would it be possible to add another parameter to the target rate sensor which allows it to calculate periods under a certain price per kWh. For example if I set up a target rate from 1am to 8am with a price of 10p and duration of 3 hours it would only return slots where the price is less than 10p and not necessarily a full 3 hours if there weren't enough slots to match the criteria. The reason for asking is that I want to charge my battery when the price is less than 10p. I get 15p for export so this gives some wiggle room for conversion loss. At the moment I have a simple trigger which turns on the charge if the price is less than 10p but if the first slot is for example 9p and later in the day there is a 5p slot it will charge during the 9p slot and not the 5p one.

Expected behavior

Couple of examples 1am to 5am. Max rate 10p Duration 1 hour

1 6p 1:30 3p 2 11p 2:30 8p 3 16p 3:30 9p 4 -1p 4:30 17p

This would return 1:30 to 2 and 4 to 4:30.

1 16p 1:30 13p 2 11p 2:30 18p 3 16p 3:30 19p 4 11p 4:30 17p

This would return nothing.

1 16p 1:30 13p 2 11p 2:30 8p 3 16p 3:30 19p 4 11p 4:30 17p

This would return 2:30 to 3 - only half an hour instead of the hour requested.

BottlecapDave commented 9 months ago

Hi. In order to support what you're after, the rate sensor would need to include two new features; max (for import)/min (for export) price and partial time blocks (for your scenario, as some people might want the sensor to not turn on at all if they can't get the right number of minutes). The config for the sensor is getting quite chunky already, so I'm trying to be more selective for features. So no promises at the moment :)

However, what you're after should be doable with a slightly more complex automation

alias: Turn on charger
description: ""
trigger:
  - platform: state
    entity_id: entity_id: sensor.octopus_energy_xxx_xxx_current_rate
  - platform: state
    entity_id: binary_sensor.octopus_energy_target_xxx
    to: 'on'
condition:
- condition: state
  entity_id: binary_sensor.octopus_energy_target_xxx
  state: 'on'
- condition: numeric_state
  entity_id: sensor.octopus_energy_xxx_xxx_current_rate
  below: 0.10
action:
  - service: home_assistant.turn_on
    ...
mode: single

This basically triggers when the current rate changes or the target rate sensor turns on (to account for the sensors potientially changing at slightly different times) and then checks that your two criteria are met. You'd then have the following to turn off the charger

alias: Turn on charger
description: ""
trigger:
  - platform: state
    entity_id: entity_id: sensor.octopus_energy_xxx_xxx_current_rate
  - platform: state
    entity_id: binary_sensor.octopus_energy_target_xxx
    to: 'off'
condition:
- condition: state
  entity_id: binary_sensor.octopus_energy_target_xxx
  state: 'off'
- condition: numeric_state
  entity_id: sensor.octopus_energy_xxx_xxx_current_rate
  above: 0.10
action:
  - service: home_assistant.turn_off
    ...
mode: single

I believe this should meet your criteria.

djdarlo commented 9 months ago

Thank you and great minds think alike. That’s exactly what I’ve done. Just waiting for todays agile rates to get published so I can test them ;)

D

On Wed, 27 Sep 2023 at 18:09, David Kendall @.***> wrote:

Hi. In order to support what you're after, the rate sensor would need to include two new features; max (for import)/min (for export) price and partial time blocks (for your scenario, as some people might want the sensor to not turn on at all if they can't get the right number of minutes). The config for the sensor is getting quite chunky already, so I'm trying to be more selective for features. So no promises at the moment :)

However, what you're after should be doable with a slightly more complex automation

alias: Turn on chargerdescription: ""trigger:

  • platform: state entity_id: entity_id: sensor.octopus_energy_xxx_xxx_current_rate
  • platform: state entity_id: binary_sensor.octopus_energy_target_xxx to: 'on'condition:
    • condition: state entity_id: binary_sensor.octopus_energy_target_xxx state: 'on'
    • condition: numeric_state entity_id: sensor.octopus_energy_xxx_xxx_current_rate below: 0.10action:
  • service: home_assistant.turn_on ...mode: single

This basically triggers when the current rate changes or the target rate sensor turns on (to account for the sensors potientially changing at slightly different times) and then checks that your two criteria are met. You'd then have the following to turn off the charger

alias: Turn on chargerdescription: ""trigger:

  • platform: state entity_id: entity_id: sensor.octopus_energy_xxx_xxx_current_rate
  • platform: state entity_id: binary_sensor.octopus_energy_target_xxx to: 'off'condition:
    • condition: state entity_id: binary_sensor.octopus_energy_target_xxx state: 'off'
    • condition: numeric_state entity_id: sensor.octopus_energy_xxx_xxx_current_rate above: 0.10action:
  • service: home_assistant.turn_off ...mode: single

I believe this should meet your criteria.

— Reply to this email directly, view it on GitHub https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/issues/423#issuecomment-1737782865, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE5PC2E37MW3I7P3TU3THATX4RMTNANCNFSM6AAAAAA5JKV3EI . You are receiving this because you authored the thread.Message ID: @.*** com>

ccristal commented 9 months ago

This is a special case of #430 .

BottlecapDave commented 2 months ago

Minimum and maximum rates are now available for target rate sensors in v11.0.0.