BottlecapDave / HomeAssistant-OctopusEnergy

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

Add Off Peak End Time Sensor #630

Closed craigrouse closed 8 months ago

craigrouse commented 10 months ago

Describe the feature

A datetime sensor which calculates the end of the next off peak period. This is already provided by the separate octopus_intelligent integration (https://github.com/megakid/ha_octopus_intelligent). I'd prefer to have just a single Octopus integration, though, partly as I don't want to double up on requests to Octopus' servers unnecessarily.

Expected behaviour

The sensor always stores the datetime of the next off peak end period. If all Intelligent slots are within the standard off peak period, the time would be 0530, but if there's a later slot that's adjacent to the end of the standard off peak time (e.g. 0530-0600), the end time would be 0600. If there are multiple adjacent slots, the end time is the end of the latest contiguous timeslot, and each time a new contiguous slot starts, the time is changed to the end of the current contiguous slot.

Use Case

I use this sensor to reset my Tesla Powerwall backup reserve settings. The Powerwall takes a few minutes to respond to changes, so I have a template sensor that uses this sensor as input, and stores a datetime that's 3 minutes before the end of each slot.

Confirmation

thewishy commented 10 months ago

https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/discussions/420 is along similar lines

Have you checked Octopus Electric Next Rate Sensor - there is an attribute for Start Time time there?

BottlecapDave commented 10 months ago

Hi sorry for the late response. As @thewishy mentioned, this will probably get added to the is off peak sensor as it will have a wider impact on users (as users on other tariffs can take advantage of this). I'll add it to the list, but not sure on timeframe as some other features currently have a high priority.

When implemented I'll add four new attributes to the sensor

Where current sensors will be unknown/unavailable if not during an off peak period and next based sensors will be unknown/unavailable if the next period isn't known.

craigrouse commented 10 months ago

Cheers @BottlecapDave @thewishy! All makes sense.

thewishy commented 10 months ago

This spurred me to looking into the issue in more detail, rather than forcing a refresh every half hour. If you want to wait a day, I've got a fairly decent workaround which nearly worked last night except for a silly error...

thewishy commented 9 months ago

This is working well for me. This would trigger 3 minutes before the rates change. For On Peak to Off Peak, you probably want a 3 minute delay so that charging starts only during off peak. Hope that's helpful!

alias: Octopus - IO Trigger
description: ""
trigger:
  - platform: time_pattern
    minutes: "27"
  - platform: time_pattern
    minutes: "57"
condition:
  - condition: template
    value_template: >-
      {{(state_attr('sensor.octopus_energy_electricity_YOURACCOUNT_current_rate','end')|as_timestamp-now()|as_timestamp)/60<30}}
    alias: Check if rate change is in next 30 mins
action:
  - alias: Check if going on or off peak
    if:
      - condition: template
        value_template: >-
          {{states('sensor.octopus_energy_electricity_YOURACCOUNT_current_rate')|float
          >
          states('sensor.octopus_energy_electricity_YOURACCOUNT_next_rate')|float
          }}
        alias: Current Rate higher than Previous rate (going off peak)
    then:
      - delay:
          hours: 0
          minutes: 3
          seconds: 0
          milliseconds: 0
      - service: notify.notify_aws_sns
        data:
          target: arn:aws:sns:eu-west-1
          message: Going off peak
          title: Rate change
        alias: Going Off Peak
    else:
      - service: notify.notify_aws_sns
        data:
          target: arn:aws:sns:eu-west-1
          message: Going on peak
          title: Rate change
        alias: Going on Peak
mode: single
BottlecapDave commented 8 months ago

As of v10.2.0.

Off peak sensor now includes attributes for current/next start/end times - https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/entities/electricity/#off-peak

Dispatching sensor now includes attributes for current/next start/end times - https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/entities/intelligent/#is-dispatching. This will include both bespoke dispatches and the standard off peak times.