I have 2 physical switches that I can control through HA.
I want to be able to control one or the other based on the time of the day using a 3rd virtual switch. This virtual switch should also mimic the state the physical switch is in.
Lets say for instance that the physical switches are called First and Second and the virtual one Virtual.
I want the Virtual switch to control the First switch from 10:00 to 13:00 and the Second switch otherwise (from 13:01 to 00:00 and from 00:00 to 09:59). It should also have exactly the same state as the switch it is controlling.
I tried a few things in HA but was not able to get the expected result.
What would be the best and easiest way to achieve this?
Thank you for your reply.
I was trying this in yaml, but I always seemed to get an error (homeassistant.exceptions.HomeAssistantError: Template rendered invalid entity IDs) : Performing actions - Home Assistant
After fiddling around with the Web UI, I managed to do what I wanted.
glad you got it to work. if you decide you want to figure out what was going on with your template approach, post your code and one of us can help identify the issue
I can control switch.first and switch.second from HA without any problem, but when I switch this virtual switch, I get the following error in the logs :
Trying the same yaml code in → developer tools → template, outputs the correct switch based on the time in the if statement, so the code seems good.
Reporting this just to try to understand where is the mistake, as the solution I finally implemented is more “elegant” from my POV.
huh… well blimey! i had it cached in my head that you can’t do that. but that doc page clearly gives an example that is what you had.
and i just tested it on a quick test it worked just fine. i think i had it flipped in my head that action/services can’t have the whole thing templated, but only the second part… so sorry about getting mixed up on that.
so now i’m confused by the error you’re getting.
It is not an automation, it is a switch template in helpers. Not sure what to post.
You can create the switch template and in turn_on add the following :
well… playing around with it, it really looks like a bug to me in the helpers. if you put that same code in dev tools->actions you’ll see that it renders fine. and it fails in the helper template.