I am trying to set-up a heating schedule, with inputs on lovelace

I can set up a Mon-Fri & Sat/Sun schedule with automations

Eg, 4pm on - 9pm off

But I would like to be able to change the 4pm / 9pm times for the automation from lovelace, without having to manually change the automation each time, this only happens a few times a year. But I would the better half to be able to adjust the heating schedule if I’m not about.

Can this be done?

Use your friend the input_datetime

Create one for each setting you want to change. Weekday/weekend/holiday/vacation…you name it. In your case, it sounds like you’ll only need 2 values (one for on time, one for off time)…

input_datetime:
  heating_weekday_on:
    name: Heating Weekday On Time
    has_date: false
    has_time: true
  heating_weekday_off:
    name: Heating Weekday Off Time
    has_date: false
    has_time: true
  heating_weekend_on:
    name: Heating Weekend On Time
    has_date: false
    has_time: true
  heating_weekday_off:
    name: Heating Weekend Off Time
    has_date: false
    has_time: true

Note, do not set initial value. If you do, it will revert to that time every HomeAssistant reboot. But you will have to set the times manually at some point at least once (via automation, or lovelace).

You will also have to add the time sensor if you haven’t already.

At a minimum, you’ll want the sensor that matches your input_datetime (time only should be fine).

Now for the automations:

- alias: Heater Morning
  trigger:
    - platform: template
      # I've set up a workday sensor that knows my work schedule. Feel free to just
      # change it to a condition: time for weekday and use another condition with the input_datetime.
      value_template: >
        {% if is_state('binary_sensor.workday_sensor', 'on') %}
          {{ states('sensor.time') == (states.input_datetime.heating_weekday_on.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}
        {% else %}
          {{ states('sensor.time') == (states.input_datetime.heating_weekend_on.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}
        {% endif %}
  condition: 
    ...
  action: 
    ...

The important part is using a template trigger to compare sensor.time to your input_datetime. I convert the input_datetime to a timestamp, then format it to match my sensor.time (which is HH:MM), then compare. This trigger is checked every minute (sensor.time is updating every minute).

platform: template
value_template: "{{ states('sensor.time') == (states.input_datetime.heating_weekday_on.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }} "
1 Like

Thank you, I got a bit carried away and copied how our thermostat works. I prefer to have automations controlled via node red so I’m using input datetime and input number. And node red updates checks once an hour.

1 Like

That’s pretty impressive (both jocnnor and mitchell). Thanks for posting! I’ve been watching for thermostat ideas, and these are among the best I’ve seen.

But I can’t help but feel that this sort of function should be built in to HA.

At a minimum, HA should do what even the cheapest “smart” thermostat on the market can do. Mine has a very simple user interface (app or web page) which allows me to set up daily and weekly schedules. Then, I can simply “up arrow” or “down arrow” to change the temperature temporarily, either from the app, the web or at the device itself. Or I can make a “permanent” change from any of these UIs, which suspends the schedule and keeps the new setting until I cancel it.

None of this is rocket science. HA does some amazing things. I can’t believe nobody has tackled this basic functionality. It seems like it should be a core component of any home automation system. The vast majority of real-world users are simply not going to write code to accomplish this.

1 Like