input_boolean:
  cheap_energy_window:
    name: Cheap energy window

template:
  - sensor:
      - name: Grid Power Mode
        state: >
          {% set watts = states('sensor.grid_power') | float(0) %}
          {% if watts < -250 %}exporting{% elif watts > 1000 %}importing{% else %}balanced{% endif %}

automation:
  - alias: Energy window marker
    trigger:
      - platform: numeric_state
        entity_id: sensor.energy_price
        below: 0.18
    action:
      - service: input_boolean.turn_on
        target:
          entity_id: input_boolean.cheap_energy_window
