Switch control depending on energy price and solar production

Why won’t it continue select a scenario? Is it too many can I do it another way?


alias: Manage Floor Heating Based on Energy Prices and Solar Production
description: >
  Turn on floor heating when prices are low (Q1), turn off during
  overproduction, and turn off if no overproduction and not in Q1.
triggers:
  - alias: If export is larger than import
    trigger: template
    value_template: >
      {{ (states('sensor.ams_ec5d_po') | float(0)) > 
      (states('sensor.ams_ec5d_p') | float(0)) }}
  - alias: If import is larger than export
    trigger: template
    value_template: >
      {{ (states('sensor.ams_ec5d_po') | float(0)) < 
      (states('sensor.ams_ec5d_p') | float(0)) }}
  - trigger: time_pattern
    minutes: "1"
    enabled: false
conditions: []
actions:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.ams_ec5d_po
            above: sensor.ams_ec5d_p
          - condition: and
            conditions:
              - condition: device
                type: is_off
                device_id: bdb56bab5f9ef9d9e0d4210ec044185f
                entity_id: 10aa6676e1da35cc7b7327853c5c5938
                domain: switch
        sequence:
          - type: turn_on
            device_id: bdb56bab5f9ef9d9e0d4210ec044185f
            entity_id: 10aa6676e1da35cc7b7327853c5c5938
            domain: switch
      - conditions:
          - condition: numeric_state
            entity_id: sensor.ams_ec5d_po
            below: sensor.ams_ec5d_p
          - condition: and
            conditions:
              - condition: template
                value_template: >
                  {{ states('sensor.nordpool_energy_prices') | float(0) > 
                  state_attr('sensor.nordpool_energy_prices', 'q2') | float(0)
                  }}
        sequence:
          - type: turn_off
            device_id: bdb56bab5f9ef9d9e0d4210ec044185f
            entity_id: 10aa6676e1da35cc7b7327853c5c5938
            domain: switch
          - delay:
              hours: 0
              minutes: 10
              seconds: 0
              milliseconds: 0
      - conditions:
          - condition: numeric_state
            entity_id: sensor.ams_ec5d_po
            below: sensor.ams_ec5d_p
          - condition: and
            conditions:
              - condition: template
                value_template: >
                  {{ states('sensor.nordpool_energy_prices') | float(0) <= 
                  state_attr('sensor.nordpool_energy_prices', 'q2') | float(0)
                  }}
        sequence:
          - type: turn_on
            device_id: bdb56bab5f9ef9d9e0d4210ec044185f
            entity_id: 10aa6676e1da35cc7b7327853c5c5938
            domain: switch
mode: single


Try

mode: queued

instead of

mode: single

Also you could simplify that by using trigger ids. If you know which trigger occurs there is no need to test the values again.

e.g.

Replace this:

          - condition: numeric_state
            entity_id: sensor.ams_ec5d_po
            above: sensor.ams_ec5d_p

with:

          - condition: trigger
            id: 0
1 Like

Or, if single execution is what you wanted, pick a previous automation trace to see what it was doing while it was triggered again.

EDIT: Having a 10 minute delay inside the automation that triggers every single minute is not something you’d want to do using queued or restart mode. It is a good thing you disabled that trigger. If you set queued, it will pile up fast. If you set restart, the 10 minutes will never finish.

So think on what you want to do during the multiple triggers, and consider using a timer and automations that run for a very short time. Using a timer you have full control of the actions after the delay.

Thank you. 1. The time pattern triggers every first minute of each hour. I disabled it to investigate why my two other triggers didn’t work. The 10-minute delay in the conditions was my attempt to mitigate rapid on/off behavior by the sensors, which can happen on sunny days with frequent cloud cover.

Thanks, I’ll give it a try and also look into what you meant by ‘ID’. I’m new to this type of markup programming.

Ah, indead. I read /1 but it says 1. Didn’t expect that :slight_smile: Sorry.

1 Like

Is the real issue here that two of my triggers is executed the same time?

16:29 - If export is larger than import - Stopped because only a single execution is allowed
16:31 - If import is larger than export - Stopped because only a single execution is allowed
16:32 - If import is larger than export - Stopped because only a single execution is allowed
16:40 - If export is larger than import - Choose: Option 1 executed On
16:43 - If import is larger than export - Choose: Option 2 executed Off, delay 10 min

Hi sonite,

I have a suggestion. You have that in every one of your choose condition statements.
I suggest removing it from all those and putting it in the

conditions statement there instead. Then that has to be true for the thing to do any actions at all.

Thanks, everyone. I learned about IDs and realized what was likely halting my automation. I cleaned up the code using IDs and changed one of the triggers to a fixed value, which should prevent both triggers from running at the same time.

alias: Manage Floor Heating Based on Energy Prices and Solar Production
description: >
  Turn on floor heating when prices are low (Q1), turn off during
  overproduction, and turn off if no overproduction and not in Q1.
triggers:
  - alias: If export is larger than 1.000W
    trigger: template
    value_template: |
      {{ (states('sensor.ams_ec5d_po') | float(0)) >  1000 }}
    id: enough_overproduction
  - alias: If import is larger than export
    trigger: template
    value_template: >
      {{ (states('sensor.ams_ec5d_po') | float(0)) < 
      (states('sensor.ams_ec5d_p') | float(0)) }}
    id: no_overproduction
  - trigger: time_pattern
    minutes: "1"
    enabled: false
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - enough_overproduction
          - condition: and
            conditions:
              - condition: device
                type: is_off
                device_id: bdb56bab5f9ef9d9e0d4210ec044185f
                entity_id: 10aa6676e1da35cc7b7327853c5c5938
                domain: switch
        sequence:
          - type: turn_on
            device_id: bdb56bab5f9ef9d9e0d4210ec044185f
            entity_id: 10aa6676e1da35cc7b7327853c5c5938
            domain: switch
        alias: Triggered by overproduction and Switch off
      - conditions:
          - condition: trigger
            id: no_overproduction
          - condition: and
            conditions:
              - condition: template
                value_template: >
                  {{ states('sensor.nordpool_energy_prices') | float(0) > 
                  state_attr('sensor.nordpool_energy_prices', 'q2') | float(0)
                  }}
        sequence:
          - type: turn_off
            device_id: bdb56bab5f9ef9d9e0d4210ec044185f
            entity_id: 10aa6676e1da35cc7b7327853c5c5938
            domain: switch
          - delay:
              hours: 0
              minutes: 10
              seconds: 0
              milliseconds: 0
        alias: Triggered by normal consumtion and high prices
      - conditions:
          - condition: trigger
            id: no_overproduction
          - condition: and
            conditions:
              - condition: template
                value_template: >
                  {{ states('sensor.nordpool_energy_prices') | float(0) <= 
                  state_attr('sensor.nordpool_energy_prices', 'q2') | float(0)
                  }}
        sequence:
          - type: turn_on
            device_id: bdb56bab5f9ef9d9e0d4210ec044185f
            entity_id: 10aa6676e1da35cc7b7327853c5c5938
            domain: switch
        alias: Triggered by normal consumtion and low prices
mode: single