Automation Failing

Stop wasting your time with weird values. 16 is fine.

Do you have a working Agile sensor yet? If you don’t see a value for the sensor that corresponds to the current Agile rate, there is no point fiddling with the automation. Show me a screenshot of that sensor — sensor.octopus_energy_cost_tracker_agile.

Ok, great,

That’s not from the rest sensor you set up. I assume from that and your other screenshot that you have an Octopus integration installed.

The state of that sensor is not your current Agile rate — its the cost you’ve incurred over some amount of time. You don’t want to be triggering the automation from that.

Have a look at the Integration screen and see if there’s a sensor provided that gives the current rate.

Is this it?

Or this;

The first one is close although that’s the next rate. You need to find the current rate. These are in £/kWh so you will want the decimal threshold e.g. 0.16 when you find the right one.

The second screenshot is the same cost sensor we were taking about earlier.

Ok, I will check this in the morning, so I find the current rate sensor and use that in the code?

1 Like

Hello, I’ve found the current rate and changed as follows…

sensor:
  - platform: rest
    name: Octopus Energy cost tracker Agile
    scan_interval: 86400
    resource_template: "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-N/standard-unit-rates/?period_from={% set ts_now = ((as_timestamp(utcnow())/1800)|round(0,'floor')|int * 1800) %}{{ ts_now |timestamp_custom ('%Y-%m-%dT%H:%M:%SZ', False) }}&period_to={{ (ts_now + 1800) |timestamp_custom ('%Y-%m-%dT%H:%M:%SZ', False) }}"
    value_template: '{{ (value_json.results[0].value_inc_vat) | round(2) }}'
    unit_of_measurement: 'p/KWH'

  - platform: time_date
    display_options:
      - 'time'

automation:
  - alias: Update Octopus Agile Price
    description: ''
    trigger:
    - hours: '*'
      minutes: '30'
      platform: time_pattern
      seconds: '0'
    - hours: '*'
      minutes: '0'
      platform: time_pattern
      seconds: '0'
    action:
    - data:
        entity_id: sensor.octopus_energy_electricity_xxxxxxxxxxxx_xxxxxxxxxxxx_current_rate
      service: homeassistant.update_entity

  - alias: Turn on Battery & Heating
    trigger:
      platform: numeric_state
      entity_id: sensor.octopus_energy_electricity_xxxxxxxxxxxx_xxxxxxxxxxxx_current_rate
      below: 20
    action:
      service: homeassistant.turn_on
      entity_id:
        - switch.livingroom_heater
        - switch.bedroom_heater
        - switch.hallway_heater
        - switch.battery_storage
        
  - alias: Turn off Battery & Heating
    trigger:
      platform: numeric_state
      entity_id: sensor.octopus_energy_electricity_xxxxxxxxxxxx_xxxxxxxxxxxx_current_rate
      above: 25
    action:
      service: homeassistant.turn_off
      entity_id:
        - switch.livingroom_heater
        - switch.bedroom_heater
        - switch.hallway_heater
        - switch.battery_storage

And this is the’current rate entity (sensor.octopus_energy_electricity_xxxxxxxxxxxx_xxxxxxxxxxxx_current_rate)

state_class: total
mpan: "xxxxxxxxxxxx"
serial_number: xxxxxxxxxxxx
is_export: false
is_smart_meter: true
tariff: E-1R-AGILE-23-12-06-N
start: "2024-03-28T08:00:00+00:00"
end: "2024-03-28T08:30:00+00:00"
is_capped: false
is_intelligent_adjusted: false
current_day_min_rate: 0.081165
current_day_max_rate: 0.33495
current_day_average_rate: 0.15729
price_cap: 100
data_last_retrieved: "2024-03-28T07:49:01.606563+00:00"
last_evaluated: "2024-03-28T08:00:01.606024+00:00"
unit_of_measurement: GBP/kWh
device_class: monetary
icon: mdi:currency-gbp
friendly_name: Electricity xxxxxxxxxxxx xxxxxxxxxxxx Current Rate

I have reset HA but it still does not work.
Thanks

Please read what I wrote more carefully. I understand that there’s lots of information here that can be confusing for a beginner, but you need to get into the detail. You’ve used 20 and 25 yet we’ve established that the rate sensor from the Octopus integration is in £/kWh not p/kWh, so you want 0.2 and 0.25.

As you already have the integration, you don’t need the rest sensor or update automation.

Things you need to do now

  1. Remove the rest sensor by deleting this code:
  - platform: rest
    name: Octopus Energy cost tracker Agile
    scan_interval: 86400
    resource_template: "https://api.octopus.energy/v1/products/AGILE-18-02-21/electricity-tariffs/E-1R-AGILE-18-02-21-N/standard-unit-rates/?period_from={% set ts_now = ((as_timestamp(utcnow())/1800)|round(0,'floor')|int * 1800) %}{{ ts_now |timestamp_custom ('%Y-%m-%dT%H:%M:%SZ', False) }}&period_to={{ (ts_now + 1800) |timestamp_custom ('%Y-%m-%dT%H:%M:%SZ', False) }}"
    value_template: '{{ (value_json.results[0].value_inc_vat) | round(2) }}'
    unit_of_measurement: 'p/KWH'
  1. Remove the meaningless update automation by deleting this code (or deleting it via the UI)
  - alias: Update Octopus Agile Price
    description: ''
    trigger:
    - hours: '*'
      minutes: '30'
      platform: time_pattern
      seconds: '0'
    - hours: '*'
      minutes: '0'
      platform: time_pattern
      seconds: '0'
    action:
    - data:
        entity_id: sensor.octopus_energy_electricity_xxxxxxxxxxxx_xxxxxxxxxxxx_current_rate
      service: homeassistant.update_entity
  1. Adjust your Turn On / Turn Off automations to use a threshold value in £, so 0.2 or 0.25.

Note that neither automation will do anything until a threshold is crossed. Please only report back once all the above changes have been made, and the current rate has either gone from below £0.25/kWh to above (“turn off” trigger) or from above £0.20/kWh to below (“turn on” trigger). If it’s not behaving as you expect, please clearly state what is and isn’t happening, not just “doesn’t work”.

Thanks for your patience,
I’ve done all of the above and checked the rates and restarted HA, this is my code now.

In Automations (for on) it says "When Electricity xxxxxxxxx xxxxxxxxxxxxx Current Rate is below 0.18
In Automations (for off) it says "When Electricity xxxxxxxxx xxxxxxxxxxxxx Current Rate is above 0.25

sensor:
  - platform: time_date
    display_options:
      - 'time'
automation:
  - alias: Turn on Battery & Heating
    trigger:
      platform: numeric_state
      entity_id: sensor.octopus_energy_electricity_xxxxxxxxxxx_xxxxxxxxxxxxxx_current_rate
      below: 0.20
    action:
      service: homeassistant.turn_on
      entity_id:
        - switch.livingroom_heater
        - switch.bedroom_heater
        - switch.hallway_heater
        - switch.battery_storage
        
  - alias: Turn off Battery & Heating
    trigger:
      platform: numeric_state
      entity_id: sensor.octopus_energy_electricity_xxxxxxxxxxx_xxxxxxxxxxxxxx_current_rate
      above: 0.25
    action:
      service: homeassistant.turn_off
      entity_id:
        - switch.livingroom_heater
        - switch.bedroom_heater
        - switch.hallway_heater
        - switch.battery_storage

I have waited until the threshold was met but it did not trigger as intended.

Many thanks

That’s not aligned to the code you pasted in; and as far as I can see your Agile price has been below £0.18p/kWh since my last post.

Show me a history graph of the sensor (the one with all the xxxxs in) including the time where you think it crosses the threshold. Like this, but for your sensor:

Then go to your Automations screen. If the Last Triggered column shows the expected time for the threshold crossing, click the three dots and select Traces. That should give a screen that looks like this:

Click the three dots top right, select Download Trace, open up that file and paste its contents in here.

This is all the information I can find, I cannot see anything that allows me to select Traces. I cannot see anywhere that shows me a Triggered column either.

I appreciate your ongoing help, if you can help me get it working I am also wanting to understand how it works and whats gone wrong so I can learn from it.
My knowledge is basic and I have been over and over it trying different things, but I am obviously missing something.

Yeah, this:

Your graph clearly shows the rate sitting below £0.18/kWh for the entire time. The trigger will only fire WHEN THE THRESHOLD IS CROSSED.

At 16:00 today your rate will jump above £0.25/kWh and the “turn off” automation should trigger. Then at 19:00 or 19:30 (not clear from the graph) it should drop below £0.20/kWh and the “turn on” automation should trigger.

These are your rates (assuming you had the correct URL in your original Rest sensor):

The blue and pink lines are the two thresholds in your automations. The red and green circles show where each automation will trigger.

That’s because you weren’t on the Automations screen. Click Settings (bottom-left, and you might want to see what those notifications are about), then click Automations and Scenes.

2 Likes

Hello, I just wanted to say that it worked, turning on and off, thank you for your patience and your help, I understand now about the threshold values and have set it accordingly. Thanks again :slight_smile:

2 Likes