How? Using one sensor's value to dynamically alter which automation triggers and conditions of a different sensor are used

I have described that horribly.

But…I want to use one sensor’s value:

  • estimated time to heat pool to temperature (hours)
    - name: "Pool Estimate Heat Time"
      unit_of_measurement: "Hours"
      state: >
          {% set pooltemprise = states('sensor.last_pool_temp_average_rise_rate') | float(none) %}
          {% set poolsettemp = states('sensor.pool1_heaters0_settemp') | float(none) %}
          {% set poolcurrenttemp = states('sensor.pool1_temperature') | float(none) %}
          {{ (((poolsettemp) - (poolcurrenttemp)) / pooltemprise) | round(1, default=none) }} 

To modify either
a) which binary sensor is called (based on sorting the 1/2hourly forecast electricity prices of Amber, and then counting up to get the highest value (thus identifying X hours are forecast to be <= the computed value.

  - binary_sensor:
      - name: "Amber Cheapest 2 Hours Trigger"
        state: "{{ states('sensor.amber_general_price')|float(0) <= (state_attr('sensor.amber_general_forecast', 'forecasts') | map(attribute='per_kwh')|list|sort).4}}"
      - name: "Amber Cheapest 3 Hours Trigger"
        state: "{{ states('sensor.amber_general_price')|float(0) <= (state_attr('sensor.amber_general_forecast', 'forecasts') | map(attribute='per_kwh')|list|sort).6}}"
      - name: "Amber Cheapest 4 Hours Trigger"
        state: "{{ states('sensor.amber_general_price')|float(0) <= (state_attr('sensor.durst_home_general_forecast', 'forecasts') | map(attribute='per_kwh')|list|sort).8}}"

or b) dynamically have the binary sensor fed by a time estimation sensor
( think multiplied by 0.2 and rounded to a single decimal (assuming less than 4.5 hours and 2 decimals if 5 or more hours)…where X is generated by the heating time estimation sensor.

- binary_sensor:
      - name: "Amber Cheapest X Hours Trigger"
        state: "{{ states('sensor.amber_general_price')|float(0) <= (state_attr('sensor.amber_general_forecast', 'forecasts') | map(attribute='per_kwh')|list|sort)X}}"

with something like

    - name: "Pool Estimate Heat Time"
      unit_of_measurement: "Hours"
      state: >
          {% set pooltemprise = states('sensor.last_pool_temp_average_rise_rate') | float(none) %}
          {% set poolsettemp = states('sensor.pool1_heaters0_settemp') | float(none) %}
          {% set poolcurrenttemp = states('sensor.pool1_temperature') | float(none) %}
          {{ (pooltemprise * ((poolsettemp) - (poolcurrenttemp)))*0.2 | round(1) }}  

Of course this doesn’t work as i’ve laid it out

Your use case is really tough to understand… - I think we should start at a higher level

Am I correct that your “final goal” is to heat the pool at the cheapest possible? :slight_smile:
For this you are using different triggers to an automation which heats the pool in 2, 3, 4, 5… hours.

Based on this I would suggest not to use different binary_sensor triggers, but ONE template sensor, based on which you are setting the heating time and then trigger by a single input_boolean.

Yes. Is particularly hard because it is one component of a much larger

I solved it in the end with:

###Trigger for Automation
binary_sensor: 
- name: "Pool Heat Time Estimate Amber Price Trigger"  
        state: "{{ states('sensor.durst_home_general_price')|float(0) <= (state_attr('sensor.durst_home_general_forecast', 'forecasts') | map(attribute='per_kwh')|list|sort)[states('sensor.pool_estimate_heat_time_corrected')|int] }}"
  - sensor:
###Estimate how long to heat the pool from current temp
    - name: "Pool Estimate Heat Time"
      unit_of_measurement: "Hours"
      state: >
          {% set pooltemprise = states('sensor.last_pool_temp_average_rise_rate') | float(none) %}
          {% set poolsettemp = states('sensor.pool1_heaters0_settemp') | float(none) %}
          {% set poolcurrenttemp = states('sensor.pool1_temperature') | float(none) %}
          {{ (pooltemprise * ((poolsettemp) - (poolcurrenttemp))) | round(1, default=none) }}        
###Convert time in decimal format to number of 30Min blocks - rounded and matched to Amber Forecast sorting starting at 0.0 for first 30min block  
  - name: "Pool Estimate Heat Time Converted"
      unit_of_measurement: "30 Min Segments"
      state: >
          {% set pooltemprise = states('sensor.last_pool_temp_average_rise_rate') | float(none) %}
          {% set poolsettemp = states('sensor.pool1_heaters0_settemp') | float(none) %}
          {% set poolcurrenttemp = states('sensor.pool1_temperature') | float(none) %}
          {{ (((poolsettemp) - (poolcurrenttemp)) / pooltemprise) | round() * 60/30-1 | round(1) }}         
###Number of Heating Blocks multiplied by 0.1 to move decimal place to correct position
    - name: "Pool Estimate Heat Time Corrected"
      state: "{{ (states('sensor.pool_estimate_heat_time_converted'))| round()*0.1 }}" 
   ### Best Amber Electricity Price for NUmber of Heating Blocks Required   
    - name: "Pool Heat Time Estimate Amber Price"  
      state: "{{ (state_attr('sensor.durst_home_general_forecast', 'forecasts') | map(attribute='per_kwh')|list|sort)[states('sensor.pool_estimate_heat_time_corrected')|int] }}"