Automation to activate thermostat scenes

Guys, can I get a little help with this automation. It’s supposed to trigger scenes to control my 3 thermostats. The scenes work, but automation is errorring out with:
Error: Error rendering service target template: TypeError: ‘int’ object is not callable

YAML:

alias: Thermostat Schedule
description: ''
trigger:
  - platform: time
    at: '08:00:00'
  - platform: time
    at: '09:30:00'
  - platform: time
    at: '21:30:00'
condition: []
action:
  - service: scene.turn_on
    target:
      entity_id: |-
        {% if (now().hour() <21) %}
          {% if (now().weekday() < 5) %} scene.weekday_thermostat
          {% else %} scene.weekend_thermostat
          {% endif %}
          {% else %} scene.night_thermostat
        {% endif %}
mode: single

You indentation for the top level if else case is not correct. Should be:

action:
  - service: scene.turn_on
    target:
      entity_id: >
        {% if (now().hour() <21) %}
          {% if (now().weekday() < 5) %} scene.weekday_thermostat
          {% else %} scene.weekend_thermostat
          {% endif %}
        {% else %} scene.night_thermostat
        {% endif %}

Or like this which I find easier to read, and I removed some unneeded parentheses:

action:
  - service: scene.turn_on
    target:
      entity_id: >
        {% if now().hour < 21 %}
          {% if now().weekday() < 5 %} 
            scene.weekday_thermostat
          {% else %}
            scene.weekend_thermostat
          {% endif %}
        {% else %} 
          scene.night_thermostat
        {% endif %}
1 Like

now().hour() is incorrect. hour is an attribute of datetime objects, not a method. It should be now().hour.

2 Likes

Fixed.

1 Like