Sian-Lee-SA / Home-Assistant-Switch-Manager

Switch manager is a centralised component to handle button pushes for your wireless switches. This includes anything passed through the event bus. The component relies on switch blueprints which is easily made to allow GUI configuration of your switches and their button pushes. This helps remove clutter from the automations.
Other
225 stars 85 forks source link

Feature request: Global presets #118

Closed proggprod closed 1 year ago

proggprod commented 1 year ago

Most of the light switches in my house are the same brands and models. Most of the time my switches are used for lights and not other automations or actions.

Can you add ‘Presets’ that can be assigned to multiple switches? This way I only need to program the default behaviour for each switch type that I have, instead of having to recreate a switch for each and every switch

Sian-Lee-SA commented 1 year ago

Each switch is an instance of a device, each blueprint is a schematic of said devices.

For your case, you'll still need to setup a switch for each device you own (this is also to match ids to said device). Next you can setup your first device then just copy the yaml from that and paste into other devices with similar functionalities. You can also create a script to all reference said script to ensure they behave the same.

Adding presets is redundant when a preset would still need to be edited to ensure they're targeting a different set of lights etc. The same time taken to pick a preset then change some targets would be the same as copying the yaml and changing the targets.

Using scripts in your sequence then using switch variables in the script calls might be what you're after.

proggprod commented 1 year ago

Thanks for the reply.

I'm brand new to HA, just installed it a few days ago, coming from openHAB. Can you point me in the right direction to understand and use variables and scripts as you descriibe? It might be close to what I'm trying to do. Maybe I need an addon for your addon. In my previous iteration of something like this, I defined the full behaviour of a light switch for a light, including switch model, up/down presses, all the multi presses, and holds etc. Then I can simply attach a light to a switch and every behaviour is enabled.

image image

Do you think I could achieve something like this with the method you suggested with scripts and variables?

Sian-Lee-SA commented 1 year ago

As you might be aware, Home Assistant utilises a sequence of actions for their automations and scripts. Scripts are generally used for a bunch of sequences that re reused over and over. Switch Manager uses these same techniques but contains them away from automations and entities. Once you familiarise yourself with Home Assistant's way of executing automations etc then it should become more clear.

I am not familiar with OpenHab so I can't describe the differences nor can I advise on how OpenHab works in comparison to Home Assistant.

But generally speaking, you can add Jinja code in your sequences Templating. if you have some kind of special sequence that you want to reuse, then you would create a Script then pass in variables. You can call this script from adding it to the sequence...

Switch Manager also provides variables which you can define from the menu in the top right, You can then access that variable with Jinja... So if you have a switch where they do the same thing but target something different. then you can simply copy the yaml from the first switch then paste into the yaml of the second switch, you could also just change the switch variable which then changes the target based on an entity or whatever you wish.

I'm also not sure on OpenHab and if it's tied with lights (I'm just basing this off the images) but the sequences and actions for a button is not tied to lights, it could simply be to start vacuuming a room, change a scene, send a notification and so on it's also possible that a button or it's action has nothing to do with an entity and could be used to reload an integration or restart Home Assistant etc.

Sian-Lee-SA commented 1 year ago

To toggle a light, just use the light.toggle service then pick the entities or area that you want the toggle to affect

Sian-Lee-SA commented 1 year ago

Added copy from in v1.2.0