Scheduler card/custom component

:tada: Scheduler integration for HA :tada:

Introduction

In my house I have quite some devices that I want to control based on the time and day. For a while I have been looking for an easy way to set up and manage the automations that control them. HA has lots of functionality, but some things (such as automations), are not as simple to use as I would like. So, I decided to create my own scheduler integration. With a mobile-friendly Lovelace card for managing it.

What is the scheduler integration?

The scheduler integration is an alternative for HA automations which use the time or sun as trigger. The integration can be used to define rules (schedules) such as:

  • Turn on the garden lights at sunset, turn them off at sunrise
  • Set my thermostat to 20C every morning at 8:00
  • Trigger a script to back-up my HA config, every Sunday at 21:00

These rules are represented as switch entities in HA. So you can turn them on/off as you desire. The time tracking and execution of the action happens on the background.
This is all maintained by the scheduler-component. I guess you could say that the scheduler-component is kind of the ā€œbrainsā€ behind the operation.

Then there is the scheduler-card. This card is a user-friendly interface for controlling the component. In a few clicks you can set up a new schedule. The entities in your HA config and the actions they support are automatically detected.

See it in action

Features

Persistent storage Once a schedule is created with the card, it will be added to HA and starts watching the time. No reloads or restarts needed. Same for editing or deleting schedules. Ofcourse they will be still there after you restart HA.

Compatibility Nearly all entity types can be scheduled, together with all possible actions (services). The card automatically checks which entities you have in HA and they will show up with their actions.

Customization The card can be set up in YAML mode or with UI editor. You can choose which device (types) you want to show up and customize display options. You can also set up your own entity configurations with custom actions, and define your own entity groups (YAML only). If you like, you can place scheduler-card in any of your Lovelace view.

Sun integration The scheduler component has support for the sun integration. You can choose to trigger a schedule at sunrise or sunset and add an offset. The time will automatically be adjusted with updates of the sun entity

Translations The card is available in 10+ languages. The language setting is automatically detected from your HA account. If yours is not there, it can be added with a little bit of help from your side.

Time schemes Time schemes allow you to divide the day in time slots. You can control what your device should do in which moment of the day.

Workday integration The scheduler component has support for the workday integration. You can use it to define how your workweek looks like and which days are your holidays. Select workdays or weekends in the scheduler and the schedules are adjusted for it.

Action retries If your entity is down (unavailable) when a schedule is due, the scheduler will wait for it to become available, and then execute the action. This is very practical with restarts of HA.

Upcoming features

Multiple entity/actions Support for turning on several devices at the same time. Or turn on the radio, set it to FM, and change the volume. Coming soon.

Conditions Only want to have your robot vacuum start if youā€™re not home? You will be able to add condition checks that check the state of HA entities before the actions are applied.

Live view The overview of the card will show how much time remaining until a next action is triggered, for each schedule.

Check the scheduler-card issue list for more ideas.

How can I get it?

You can download the files directly from GitHub and add them to your HA config, but also HACS is supported. Follow the instructions on the GitHub pages.

The scheduler-card for Lovelace:

The scheduler-component:

Support, issues and feature requests

If you run into trouble setting up the integration in HA or you donā€™t know how to use the scheduler, please ask your questions here in this thread. Many users have walked the same road as you do, so its usually a quick fix.

For issues (bugs) and feature requests, please use GitHub.
Make sure that you choose the right repo (scheduler-component vs scheduler-card) for your issue or request. Also check if if there is already an open issue for it.

Say thanks

If youā€™re really happy with the scheduler, consider buying me a coffee!
In this way you motivate me to keep supporting my work. Thank you!

124 Likes

Nice! Any plans to make an HA addon?

1 Like

Looks awesome! Nice work. HA definitely needs something like this!
Just wondering why it needs MQTT and node.js? Why didnā€™t you use HA event bus for attaching triggers?

Thanks!
Uuhm, I am not familiar with HA add-ons.
Is this the way of installing externals when running hass.io?
A quick look on this page tells me an HA add-on is little more than a Docker container, so it definitely looks doable.
Personally I run HA as a Docker in raspbian, so for me there is no need for using the add-ons, but I could provide support for it, sure.
It will require a testing :rabbit: thoughā€¦

Thanks!
Yeahā€¦ I think HA has extensive possibilities, but almost everything requires YAML skills. There is some improvements towards GUI based configuration, but still it is not as easy to use as I wanted it.

Since about a year ago I stopped using automations with a time: trigger, since they didnā€™t always fire.
So I decided to do the timekeeping outside of HA.
But I donā€™t know if they became more reliable over time.

I am not much of a python wizard, so the custom component I made is now very simple, it only forward calls from the Lovelace card to the node.js app through MQTT.
But I saw there is there is a straight-forward method to set timers within the custom component, so it seems quite possible.

I can imagine people donā€™t like setting up the scheduler-app, so I will definitely investigate if I could merge all its functionality with the custom component.
Based on your feedback and that of others, I can determine if this should be a priority.

3 Likes

Hass.io addons are basically a container. A pretty simple example is another scheduler.

1 Like

I would vote for leaving it as a custom_component then also core users can use it.

6 Likes

Well, to be honest HA requires less and less YAML skills almost with ebvery release. Automations which are the core part of the system do not require YAML. Unless one wants sth more sophisticated and tempalte usage is required. UI layout can also be built quite quickly just by clicking.
But for more advanced config - yeah, YAML is still important.

Weird. I use a couple of automations with time trigger and they never disappointed me. They always fire. If something doesnā€™t fire tat means either integration (component) issue, or automation conditions were not fulfilled. HA is very reliable in my opinion. I developed a custom component (integration) and learned its architecture and it is really good. It just worksā€¦like magic :wink:

Yeap, you could use that or just register your component to listen for a proper time-date event. I know there is one fired every second and minute when time changes. I can search it for you. Once event fires your code will intercept it and can act upon it. Iā€™d do it this way. Iā€™m also not a python wizard, neither did I go very deep in HA programming, but I can say I learned some common solutions for various issues with component development.

From the same reason that people avoid YAML - also installation and setup should be as easy as possible. To me the more components a solution depends on - the worse. At the beginning of my work with my custom integration I developed simple python scripts that sent messages to HA via MQTT. It worked well, but administrating this was sometimes a bit painful. Once I switched my development to a new approach of building a custom component directly in HA - my work gained traction with users and people just started using it because it was easy, as easy as other integrations in HA. People knew how to setup the integration, how to administer it etc. So yeah - I think building your component only as a HA extension, dripping node.js and MQTT should be your priority. People will really appreciate it. Your GUI is very good. I think it could be part of HA core and to me getting rid of additional components will only help.
I advise you to have a chat with HA core developers in Discord. They are friendly and they help a lot. I also advise you to browse through HA components like Hue, z-wave, automations. This helps to understand how things should be done.

I keep fingers crossed fr your efforts! This component can really be a HA smash hit!

1 Like

This looks promising. I like your UI style. Just wondering how it scales up with lots of entities. Maybe you have to redo the engine to make it more user friendly (to install) but Iā€™m sure it will be worth it.

Likewise. I have plenty of time triggers and theyā€™ve never missed a beat.

Neat custom integration though. Well done neliss.

1 Like

Many thanks for all feedback so far!
I made some progress with the custom_component, the timekeeping which was done in the Node.js app, is now a part of the custom_component.
The Node.js app was also responsible for storage of the entities (persistence), this is moved to the custom_component as well.

This means that the Node.js app is not longer required.
For the time being the custom_component still relies on retained messages on MQTT for ā€˜discoveringā€™ the entities after restarting HA, but Iā€™m looking into a proper way (such as generated YAML or database storage).

To be continued!

6 Likes

Iā€™m having trouble configuring it, mind sharing a full config dump of your card?

1 Like

Wow! Awesome progress! Looking forward for dropping MQTT as well! Keep up the great work! Once you do it - Iā€™d vote for making this an official HA integration. This functionality is missing for so long, that they need to make it part of HA by default once :slight_smile:

1 Like

Sure thing!
It was rather long for posting here, so i added it to the repo.

A barebones starting config would be:

type: custom:scheduler-card
groups: # groups define the options you can choose from when you make a new entity 
  all_lamps: # gives a group labeled 'all lamps' with all light entities under it
    domains: [light]
  my_filter: #gives a group labeled 'my filter' with only 1 entity under it
    entities: [fan.my_filter]
# note that each entity or domain used in a group, needs to have at least 
# 1 action defined for it (else it would become a stub - could cause crashes)

domains: # add here the settings you want to apply to each entity of a type
  light: # all lights will have a 'turn on' and 'turn off' action
    actions:
      - service: turn_on
      - service: turn_off

entities: # add here specific entities with their actions
  fan.my_filter:
    actions:
      - service: turn_on
        service_data: {speed: high}
      - service: turn_off

You can prettify the visualization of the card by adding name:'my name' or icon:my-mdi-icon properties (you can do this per group, per entity, per domain and per action).

Currently the code is not very forgiving: if you make a typo, the whole card will not show up.
Also the groups/domains/entities configurations are currently mandatory, meaning that you will have to put at least 1 item (so above example is also close to a minimum configuration).

I am aware that it it a bit cumbersome and confusing to configure the card. Keeping it user-friendly is one of the key goals, so you can expect improvements here.

Thanks :slightly_smiling_face:
I would like to drop the MQTT asap as well, but this was the best i could achieve for now. I asked for assistance on the Discord chat (thanks for the tip!), because I need to find out how to create entity persistence (without having to define them in YAML). So far no useful input, but weā€™ll see.

Did you post it on devs_core channel? Discord?

Basically if you create entities HA takes care of their storage automatically. I think what youā€™re looking for is State Attributes.
Iā€™ve seen in your code you already handle it. Then whenever you want to store something in there just call self.async_schedule_update_ha_state(True) and you should be fine.

However if you want to store something (e.g. config data) because you want to keep that between HA restarts then Iā€™m not sure whatā€™s the best way, but I know a common solution is to output such things to a file. Google Calendar and Z_Wave integrations do it. See here: https://github.com/home-assistant/core/blob/d058802325598ab44e319f65525045295781e366/homeassistant/components/google/init.py#L392

The icons are offset for me:


If you canā€™t see it itā€™s the forumā€™s problem, right-click on the image, open in new tab, advanced, proceed.

Woah that looks bad!
Seems like the complete CSS config of the card is being ignored.
I must say i have seen something similar a few times, but it was gone after refreshing.
It is a bit of a cliche, but did you try (force) refreshing the browser?
I tried this card with the default HA theme, do you maybe use an alternative theme?

I force refreshed and itā€™s working now!

Thanks for your work! It looks awesome :slight_smile: and I have been looking for this functionality in HA for quite some time now.
I didnā€™t try it yet thoughā€¦ I am waiting for it to be in a more stable phase and my coding skills are limited.
Any updates since the last comments? Should I give it a try already?
Thanks again :smiley: