Intelligent Octopus Sensors

Post Reply
Dave Foster
Posts: 1294
Joined: Thu Oct 13, 2022 7:21 pm

These sensors are derived from the 'unofficial' octopus home assistant integration by bottlecapdave.

If you have Octopus Intelligent, the integration provides additional sensors which includes a flag that indicates when an intelligent slot is in operation.

Within some of the sensors are 'attributes' that contain the next and forthcoming planned dispatch slots.

The following sensors simply convert the attributes into usable start and end time sensors, which when combined with the flag can be used to set charge times, or simpy to notify you how long the slot is (these can be anything from 30 minutes to 12 hours).

These sensors should be added to the 'Template:' section of your configuration.yaml

The first 2 are IO next slot start and end, if a slot is planned they will return the start and end times of the slot, if a slot is not set then they will return "00:00:00"

Code: Select all

  - sensor:
      - name: IO next slot start
        state: >
            {% if state_attr('binary_sensor.octopus_energy_intelligent_dispatching', 'planned_dispatches') | length > 0 %}
                {% set start= state_attr('binary_sensor.octopus_energy_intelligent_dispatching', 'planned_dispatches')[0].start |as_local %}
                {{ start.strftime('%H:%M:%S') }}
            {% else %}
                {{ "00:00:00" }}
            {% endif %}
      - name: IO next slot end
        state: >
            {% if state_attr('binary_sensor.octopus_energy_intelligent_dispatching', 'planned_dispatches') | length > 0 %}
                {% set end= state_attr('binary_sensor.octopus_energy_intelligent_dispatching', 'planned_dispatches')[0].end | as_local %}
                {{ end.strftime('%H:%M:%S') }}
            {% else %}
                {{ "00:00:00" }}
            {% endif %}

This next sensor is similar to the planned dispatch sensor in that if the current time is within a planned slot it will return true

Code: Select all

      - name: "IO slot active"
        state: >
            {% set a=namespace(start=0) %}
            {% set a=namespace(end=0) %}
            {% set a=namespace(match=false) %}
            {% if state_attr('binary_sensor.octopus_energy_intelligent_dispatching', 'planned_dispatches') | length > 0 %} 
                {%- for dispatch in state_attr('binary_sensor.octopus_energy_intelligent_dispatching', 'planned_dispatches') -%} 
                    {% set a.start = dispatch.start | as_local %}
                    {% set a.end = dispatch.end | as_local  %}
                    {% set temp = now() %}
                    {% if temp >= a.start and temp <= a.end %}
                        {% set a.match = true %}
                    {% endif %}
                {%- endfor %} 
                {{ a.match }}
            {%- else -%} 
                {{ a.match }}
            {%- endif  %}

Post Reply