Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 105813

Template, time_pattern with condition fails

$
0
0

Hi,

I’m creating a binary sensor that should be On during the most cost effective hours during the night (9pm-5am). This will be used in an automation that charges my electric bike during the cheapest hours at night.

I’m using the Nordpool integration as source; using the state attribute today to pick up the hourly rate between 9pm and midnight, and the state attribute tomorrow for the hourly rate between midnight and 5am.

The tomorrow attribute updates by the Nordpool integation around 1-2pm daily, and clears it sometime after midnight.

The following code works and updates the binary sensor at 8.40pm. And, it makes use of a Dropdown helper called input_select.nattladdning to set how many hours it should be charging (2,4 or 6).

template:
  - trigger: 
      - platform: time_pattern
        hours: 20
        minutes: 40
    binary_sensor:
      - name: "Nightly charge"
        state: >
          {% set hours_on = int(states('input_select.nattladdning')) %}
          {% set price_now = float(states('sensor.nordpool_kwh_se4_sek_3_095_0')) %}
          {% set nighprice = state_attr('sensor.nordpool_kwh_se4_sek_3_095_0', 'today')[21:]+ 
             state_attr('sensor.nordpool_kwh_se4_sek_3_095_0', 'tomorrow')[:5] %}
          {% set average_on = average((nighprice | sort())[int(hours_on-1)], 
                                      (nighprice | sort())[int(hours_on)]) | round(3) %}
          {% if price_now < average_on %}
          On
          {% else %}
          Off
          {% endif %}

However; I would like to ensure this template survives a restart, and therefore I’d like to have it updated every 5th minute between 2pm and 11.45pm. It cannot update itself after midnight and before the ‘tomorrow’ prices has arrived.

The following code throws an error:

template:
  - trigger: 
      - platform: time_pattern
        minutes: '/5'
    condition:
      - condition: time
        after: '14:59:00'
        before: '23:59:00'
    binary_sensor:

Logger: homeassistant.config
Source: config.py:929
First occurred: 08:02:43 (1 occurrences)
Last logged: 08:02:43

Invalid config for [template]: [condition] is an invalid option for [template]. Check: template->condition. (See /config/configuration.yaml, line 103).

Suggestions welcome…

/Marcus

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 105813

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>