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

Automation service template using times in if else block fails

$
0
0

I’m attempting to merge two working simple automations into one because having one automation to switch on a thermostat and a second automation to switch it off lacks elegance and means two automations have to be managed.

I’m attempting to create my first service template which uses a very basic if/else block based on times. The times come from helpers, the values are input from lovelace.

All that has to happen is the generic thermostat is switched on if it’s within the on and off times. Simple, right? Code below. I think I’m probably tangled up in time formats but there may be more. I’ve spent hours reading finity’s EPIC Time Conversion thread and searching. I’ve gone snowblind :cry: Why is this automation not turning the thermostat on and off?

- id: '1612078816753'
  alias: Warm the bed 2
  description: description
  trigger:
  - platform: time
    at: input_datetime.underblanket_on
  condition: []
  action:
  - service_template: >
      {%- set t_now = now().time() %}
      {%- set t_on = strptime(input_datetime.underblanket_on, '%H:%M') %}
      {%- set t_off = strptime(input_datetime.underblanket_off, '%H:%M') %}
      {% if t_now >= t_on and t_now < t_off %}
        climate.turn_on
      {% else %}
        climate.turn_off
      {% endif %}
    data: {}
    entity_id: climate.underblanketthermostat
  mode: single

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 105696

Trending Articles



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