Help me create a simple switch schedule

Hi folks,
Maybe I am missing something (and I usually do) but I thought what I wanted to do would be bread and butter simple, alas no it seems.

All I want to do, is create a scheduled timer (timer, scheduler) to control a sonoff in Home Assistant. I imagined there would be an off the shelf control with a nice graphical interface that I would just add to a card and choose my switch entity from a drop down, but I cant seem to find any such thing. I have been searching and struggling now for over two hours and have gotten nowhere.

I’d like to be able to schedule a switch ON at any given time(s) on any given day(s) and the same for OFF. e.g. Switch ON at 6pm and switch OFF at 7:10pm on mon, tue, wed, thur, fri, Switch ON at 10am and OFF at 11am on sat and sun. I’d like to be able to change this schedule easily hopefully via UI or mobile phone GUI.

Searching Youtube, google etc, all I am seeing are some forum posts with horrid and complex yaml and templates that I cannot get working. I have watched videos about node red, home assistant etc. I have looked at the home assistant timer, no good.

What am I doing wrong?

BTW this is kinda typical of my experience of getting anything up and running in HA. Awful yaml, awful templates, wasted time spent troubleshooting, frustration, exhaustion from failure etc. Why cant it be a bit more graphical now? a bit more intuitive? Have the yaml as an advanced configuration tool but all the plain and simple stuff should be easy surely - its 2020!

It’s possible to write something with input_text and input_number and lots of input_boolean to make it suit your needs and im also sure someone might have already something ready to share (or some add-on through HACS).

On another note, when i needed something similar for a remote location irrigation control, i flashed a sonoff-4ch with tasmota and used their built in timers function. Here’s an idea of how it works on a sonoff-basic:

Just my input in case it easily solves your problem with minor effort.

1 Like

This project still in beta, devs are working hard to make more and more things configurable via the frontend and they already made progress with the automation editor, scene editor etc. This is open source, feel free to contribute yourself :wink:

What you want to do doesn’t sound that complicated. Create four input_datetime, one for ON time weekday, one for OFF time weekday, one for ON time weekend and one for OFF time weekend.
Then create 4 automations, one for each of the four scenarios, which trigger on the specified time in the input_datetime. And if you want to go one step further you can combine these 4 automations into one and do stuff based on the trigger.
I can write something up in case you are interested.

1 Like

the person hasn’t even figured out how to write some simple automations yet. they can’t really be expected to “contribute” anything yet. We need to lay off the “if you don’t like it then do it yourself” thing. it sounds kind of condescending especially to a new person experiencing the initial learning curve of HA/YAML.


Hi guys and thank you both for the replies. Yes I do appreciate FOSS software and the great work of the community. I appreciate both your ideas but they seem somewhat complicated for what I am trying to do. It is worth nothing that HA is 4-5 years old if I am not mistaken, in all that time I like to see some progress and advances in usability and making the thing intuitive. A programmable timer in my opinion should be home automation 101. It should be right there, in my face and as easy as pie to use.

I know, this was not meant so serious… However I’m fed up with people coming here, with no real experience (assuming from the post) that started to use HA only recently and then comments like “it’s 2020!”. I repeat myself it’s a beta product, and as a new user you either accept this and deal with a steeper learning curve, doing thing in YAML etc. or wait for it to reach version 1.0 and then come back again. At the current stage it’s not plug-and-play and all graphical config etc., it made huge progress in this direction but it is still BETA.

If this is too complicated, then I suggest using another home automation software and wait until home assistant is more advanced. At the current stage there is still a lot that needs to be configured manually, it’s not plug-and-play.

There was a lot of progress in this direction. Do you know how it was a few years ago?

Also if you would have searched the forum, you would have seen that there are feature requests for a scheduler already. I strongly suggest not watching youtube videos (they are mostly outdated with such a fast paced product) or searching google but rather read the documentation and search the forums.

I take your point, but just because its open and free software, shouldn’t render it immune from criticism. My comments reflect my reality using this software. I have been measured, appreciative of the community but wish to vent my ongoing frustration in using this platform. The timer is just the latest experience for me.

1 Like

Yes of course criticism is allowed and welcome :slight_smile: However a bit in a more appropriate way and not such as “hey it’s 2020, this should be already available” :wink: Maybe I just took it a bit too serious…

Search the forum for the feature request, vote and maybe even post your ideas if they are not already mentioned in the feature request. When the feature request gets enough attention the devs may take a look at it, but I can tell you for sure that most of the devs will not take a look at this post here and consider your criticism. Would be better to open a Github issue then.

from this I’m kind of not sure I buy that:

but whatever, my point was that there are less “unfriendly” ways to say that to someone who is just doing a little venting when every one of us has been in a similar situation. And IMO the OP wasn’t being disrespectful to the software but just voicing a bit of surprise that something as basic as a scheduler isn’t already included.

I repeat myself too and say that we (the HA community) need to get a bit thicker skin and stop being so overly sensitive to any perceived criticism and accept that to some (especially new) people not everything with HA is perfect and simply saying so isn’t any reason to circle the wagons and tell them to “bugger off if you don’t like it”. It could just be that some dev hasn’t thought of that aspect yet and a mild criticism could be useful to prod them in the right direction. If we are all just a bunch of “yes-men” and acted perfectly satisfied with the way things are then there would be no reason to make improvements.

1 Like

I agree with you. This “it’s 2020” just sounded too harsh for me, I realize now that he probably didn’t mean it like this.

I was more saying, that if setting up this something like this schedule is too complicated and too much for a person, then I really think HA is not for them (yet) and they will have a really, really hard time with it. And they will get frustrated a lot more when they try to set up more complex things.

If one would search the forum, he would see that there are multiple requests and topics already about this and I think it would be more appropriate to continue the discussion there.

1 Like

Maybe but not necessarily. The OP has only signed up a couple of weeks ago. So I think that sometimes people start trying to do more advanced stuff before they get a good handle on the basics and that fact alone could lead a lot of new people to early frustration.

And, I think that, tho it may seem simple for people who have been around for a while, a scheduler that might need multiple input_datetime’s, booleans, automations & scripts to all succesfully interact is pretty complex.

I agree with that. My comment was just about “mild criticism” in general.

Never thought of it this way. But I just realize that it was the same for myself minus the frustration :sweat_smile: I just accepted that it is complicated and searched and read a lot to solve my problems, however this was more than 2 years ago and there it was way more beta than now :slight_smile:

1 Like

If this is only for one switch and you are interested I can write something up for you, however for multiple switches with different schedules, you may take a look at Schedy. It requires some initial setup but afterwards its easy to configure and has a lot of advanced functionality as well. I totally forgot about this app.

Thanks all for the replies. Look! the way I see these kind of situations is

We are all members of this community now. As soon as I started using HA and joined this forum I became another. I am a newbie, some others are dinosaurs :slight_smile: we both bring our own baggage to each interaction.

I will look into Schedy, thanks for that.

1 Like

Hey dude,

I’m in the middle of sorting something like this out in this thread:

if you wanted to take a look. As you’ll see I’m having some issues, but if you take a look at my automations.yaml files as posted as well as configurations.yaml you’ll be able to see how it might work.

Some gotchas which took me a while to figure out:

  • The time condition which checks to see which day of the week to do something on isn’t readable/writeable from the GUI you have to add it into the automation.yaml file with a text editor
  • To be able to change times/dates/etc as variables you have to create them as entities in configuration.yaml - check in my post for lines like ‘hws_mo’ - you’ll see there’s a separate one for each day of the week. Once these entities exist, you’ll be able to add them as entities in the Lovelace UI which you can edit
  • In the automation, you’ll need to use the template trigger to check is the set time is the current time
'{{ states(''sensor.time'') == (states.input_datetime.your_entitiy_variable_name.attributes.timestamp
      | int | timestamp_custom(''%H:%M'', False)) }}'
  • I found it easier to create the automations in the GUI for the days of the week with basic triggers and so on and then edit the yaml later rather than try to write the whole automation from scratch, helps with the formatting and so on.
  • If you have to edit text files on the command line (with nano or vim) be careful about copy and pasting stuff from sublime/notepad/textedit/etc because the tabs/spaces/linebreaks etc can change and you’ll spend an hour trying to figure out why its broken. (this might just be a note to myself actually…)

The approach here is that checking that it is a certain time on a certain day is tricky. Instead, check for the time every day, and then use a condition, to only do the thing you need to do, if the day is correct. There’s lots of repeated code and copy-pasting which feels inefficient but while you’re getting things set up it probably makes things easier to debug.

If you need anything more sophisticated than this Schedy is probably the way to go.

Good luck!

1 Like