Heating timer

I currently have HA running my heating schedule using a basic automation. The automation as it stands, activates between certain times using the before / after conditions, and through this period, it sets the climate based on a slider value, which represents that period of the day.

I have automations for morning heating, evening heating, and ‘beween’ heating, each of which has its temperature slider. the automation for each is an iteration of the automation below,

- alias: Weekend Morning Heating
  id: weekendmornHeat
  trigger:
  - platform: time
    seconds: '/10'
  condition:
  - condition: time
    after: '09:00:00'
    before: '10:00:00'
  - condition: state
    entity_id: binary_sensor.workday_today
    state: 'off'
  - condition: state
    entity_id: input_boolean.vacation_mode
    state: 'off'
  - condition: state
    entity_id: input_boolean.school_holidays
    state: 'off' 
  action:
    - service: climate.set_temperature    
      data_template:
        entity_id: climate.lounge
        temperature: '{{ states.input_number.morning_temp.state | float }}'

What i would like to do, is use the input select function to set the before and after time.

after: '{{states.input_select.weekend_morn_on.state}}'

which returns, as an example 06:30:00

when i try this, i get all sorts of Jinja errors, which im not to certain on how to correct.

Invalid config for [automation]: extra keys not allowed @ data[‘condition’][0][‘after’]. Got None
not a valid value for dictionary value @ data[‘condition’][0][‘condition’]. Got None
required key not provided @ data[‘condition’][0][‘entity_id’].

Does anyone have any advice?

Or i am i just being hopeful that a template will work for time…

You can use a template condition for this, rather than trying to put a template in to a time condition (which you can’t do, as you’ve discovered).

I’ve managed to ‘fudge’ my way around this, it may not be pretty, but it works.

I have automations which check an input_number slider, and if there are any changes to the slider, while the automation is in zone, it changes the target temperature in climate.

My hope was to have a input_select to adjust the on off time, which now I know cant work.

My resolution was to create a further set of automations, which activate on the time set by the input_select, and switch on / off the other automations which are looking at the temperature sliders.

Long winded but it works.

Examples of code below:
input_select:
weekday_morn_on:
name: ‘Weekday Morning On’
icon: mdi:alarm
#initial: ‘06:30’
options:
- ‘06:00’
- ‘06:15’
- ‘06:30’
- ‘06:45’
- ‘07:00’
- ‘07:15’
- ‘07:30’
- ‘07:45’
- ‘08:00’
- ‘08:15’
- ‘08:30’
- ‘08:45’
- ‘09:00’
- ‘09:15’
- ‘09:30’
- ‘09:45’
- ‘10:00’

automation to check slider

- alias: Weekday Morning Heating
  id: weekdaymornHeat
  trigger:
  - platform: time 
    seconds: '/10'
  condition:
  - condition: state
    entity_id: binary_sensor.workday_today
    state: 'on'
  - condition: state
    entity_id: input_boolean.vacation_mode
    state: 'off'
  - condition: state
    entity_id: input_boolean.school_holidays
    state: 'off'   
  action:
    - service: climate.set_temperature    
      data_template:
        entity_id: climate.lounge
        temperature: '{{ states.input_number.morning_temp.state | float }}'



- alias: WDmornOn_WDbt3Off
  trigger:
    platform: time
    #as all timings are in 15 minute blocks, triggering the check every 15th minute will suffice
    minutes: '/15'
  # this will report true if time in input_select (in format HH:MM ) is equal to actual time  
  condition:
    - condition: template
      value_template: '{{states.sensor.time.state == states.input_select.weekday_morn_on.state}}'
  action:
  #our action should be to enable the next automation, and disable the previous automation
  - service: automation.turn_on
    entity_id: automation.weekday_morning_heating
  - service: automation.turn_off
    entity_id: automation.weekday_between_heating3

It can work if you use the correct trigger type, as I described above. Zero fudging required.

Unfortunately my skill set is limited, and im still attempting to self teach all of this. I’m not too well versed at all in template conditions. I’ll keep plodding through.

Is all you want just to have this be the same as the input select?

after: '{{states.input_select.weekend_morn_on.state}}'

Try double quotes instead of single, like this:

after: "{{states.input_select.weekend_morn_on.state}}"

It results in the same error. Im just attempting some further templating, to see if i can get on top of it.

- alias: Weekday forenoon Heating
  id: weekdayforenoonHeat
  trigger:
  - platform: time 
    seconds: '/10'
  condition:
  - condition: template
    value_template: '{{( states.sensor.time.state <= states.input_select.weekday_eve_on.state ) and (  states.sensor.time.state >= states.input_select.weekday_eve_off.state)}}'
  - condition: state
    entity_id: binary_sensor.workday_today
    state: 'on'
  - condition: state
    entity_id: input_boolean.vacation_mode
    state: 'off'
  - condition: state
    entity_id: input_boolean.school_holidays
    state: 'off'   
  action:
    - service: climate.set_temperature    
      data_template:
        entity_id: climate.lounge
        temperature: '{{ states.input_number.morning_temp.state | float }}'

This is my attempt using templating, Unfortunately, I have to wait until tomorrow to get it all checked, as its time to shut down for the night

You can try if this fixes it:

after: "{{states('input_select.weekend_morn_on')}}"

Just be sure that the input_select throws 06:30:00 and not 06:30 as an example.

I have tried multiple attempts using templates under the time function, including what you are suggesting now, but i don’t believe they work at all, hence the fact i am now trying to use templating as a condition. Thanks for the tips though.

You are correct. Value_templates cannot be used under the time condition :frowning:

i’ve tested this and it works to control the heating :smiley:

- alias: Weekday Evening Heat Schedule
  id: weekdayEveningHeat
  trigger:
  - platform: time 
    seconds: '/10'
  condition:
  - condition: template
    value_template: '{{( states.sensor.time.state >= states.input_select.weekday_eve_on.state ) and (  states.sensor.time.state <= states.input_select.weekday_eve_off.state)}}'
  - condition: state
    entity_id: binary_sensor.workday_today
    state: 'on'
  - condition: state
    entity_id: input_boolean.vacation_mode
    state: 'off'
  - condition: state
    entity_id: input_boolean.school_holidays
    state: 'off'   
  action:
    - service: climate.set_temperature    
      data_template:
        entity_id: climate.lounge
        temperature: '{{ states.input_number.evening_temp.state | float }}'

Great job😊 think you can use your template condition as trigger instead of time every 10 seconds. Then you don’t have to spam the system too much.

the 10s job is looking for any changes to the heating target. i need to trigger some other form of job to reflect that!

not sure I follow you. I mean, the template should check itself every minute itself due to the sensor. time in your template. But mayby I misunderstood what you need to achieve, or maybe the template doesn’t do as I think it should :stuck_out_tongue:

I was thinking kind of like this for alarm clock, just with your template instead:

automation:
  - alias: 'Hue light on gradually with alarm'
    hide_entity: False
    trigger:
      platform: template
      value_template: '{{ states.sensor.time.state == states.sensor.alarm_clock_time_long.state }}'
    condition:
      condition: state
      entity_id: input_boolean.alarm_clock_status
      state: 'on'
    action:
      service: script.wake_up

But maybe it will not work as I think, or updates once a minute is too slow for what you want to achieve.