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

Added Shelly 1 blueprints for installation with momentary button or rocker switch #100

Closed robotanik closed 1 year ago

robotanik commented 1 year ago

Blueprint Checklist

Sian-Lee-SA commented 1 year ago

For the switch, would it not be better to have separate on and off actions while also having init action?

Sian-Lee-SA commented 1 year ago

Also is there no event data that handles this instead of entity?

robotanik commented 1 year ago

Sadly the shelly.click event only fires when the input gets a high state. On a rocker switch it fires a long click for one of the state changes after the long click time. A separate action for from off to on or the other way would be a good option.

robotanik commented 1 year ago

Apparently the newer Shelly Plus modeles have an event for button down and button up. But the first generation does not have this.

Sian-Lee-SA commented 1 year ago

I see a few problems with this. Firstly, state_changed is discouraged because in gerneral, it goes against the standard for (switches) but I understand this one is not a stateless switch so I can understand an entity for it (so even though it's an issue, I can still accept it as there's no other method to get the state).

Secondly, Auto discovery would be very flakey if a user happens to have any entity change from on to off or vise versa which can happen quite alot (is there any other attribute or such to scope in on the device?).

I did a search about the button version and it seems to be a physical button device so I think using an image that represents the device would be desired. https://www.expert4house.com/690-large_default/shelly-button-1.jpg.

For single switches that is a module, I am starting to think an image of just the module would be more appropriate (I will probably update other switches that are just modules) but multiple buttoned modules should use a singular generic button image (not valid in this PR) (I also don't like the current image with the module in the corner of the switch as it causes too much padding, if it fits within the generic switch art and the switch itself is cropped to the borders then thats fine).

It's taken me a while to wrap my head around the shelly devices and how the author made the original blueprint without defining that it's a buttoned version because it was very unclear to me so that's why I have spend a while googling these devices....

I encourage to use key, value pairs where possible. So the actions for the switch should use the key and value array but the root template conditions are fine as it makes sense there. You also don't need to check the old state in the actions as the root condition has already validated this. So checking the current condition will suffice.

Lastly, toggle should be renamed to init as the init will be common language within this project to mean it will execute on any action which in this case it will for both on and off.

robotanik commented 1 year ago

Secondly, Auto discovery would be very flakey if a user happens to have any entity change from on to off or vise versa which can happen quite alot (is there any other attribute or such to scope in on the device?).

For better identification there is the device_class = "power" in the new and old state. But I do not know if this would be helpful. This could be different depending how you configure the device class in the shelly software. I attached an state_canged Event.

I did a search about the button version and it seems to be a physical button device so I think using an image that represents the device would be desired. https://www.expert4house.com/690-large_default/shelly-button-1.jpg.

With button I meant the installation of the module with a momentary button and not a rocker switch. The Shelly button is a another device.

Sian-Lee-SA commented 1 year ago

Does the following not work?

buttons:
  - actions:
      - title: init
      - title: 'on'
        conditions: 
          - key: new_state.state
            value: 'on'
      - title: 'off'
        conditions: 
          - key: new_state.state
            value: 'off'
Sian-Lee-SA commented 1 year ago

You mention the button one i showed a picture of is a different device, considering when that device gets added it would make sense to call it shelly 1 (button) as such so yours should probably be techincally a module shelly 1 button module or something alike... file names are more important in this aspect.

robotanik commented 1 year ago

Does the following not work?

No. This does not work. Have you an idea why this does not work?

robotanik commented 1 year ago

The stand alone device is called Shelly Button 1 and the Module for installation is called Shelly 1. So depending of the installation on needs the shelly-shelly1-buttonmodlue or the shelly-shelly1-switchmodule. For the standalone device on could chose shelly-shelly-button1?

Sian-Lee-SA commented 1 year ago

I understand the module is an installation for the shelly button it's just for user convenience if they're unaware so they can choose the button as a prebuilt device (I would expect people to know once they're involved in these products but I'm sure there's some that doesn't know they're the same as they are technically sold as seperate products).

I will test a dummy event to see if it works but it should do. Will update once I figure out whats going on with that.

Sian-Lee-SA commented 1 year ago

Turns out that the event data handled through Python for state_change uses the state classes instead of a dictionary (pretty unique) and seeing as you're the first to do a blueprint involving state_change for an entity this has never popped up before. I will convert this in code to do a dictionary which will then allow the key and value pairs to work. After I post a new release, could you please confirm with the key value pairs works then I can merge. Thanks.

Sian-Lee-SA commented 1 year ago

Please update to Release 1.0.2 and try the following

name: Shelly 1 (switch)
service: Shelly
event_type: state_changed
identifier_key: entity_id
conditions: "{{ (data.old_state.state == 'off' and data.new_state.state == 'on') or (data.old_state.state == 'on' and data.new_state.state == 'off')}}"
buttons:
  - actions:
      - title: init
      - title: 'on'
        conditions: 
          - key: new_state.state
            value: 'on'
      - title: 'off'
        conditions: 
          - key: new_state.state
            value: 'off'
robotanik commented 1 year ago

Now it works. Thank you very much for the guidance and the quick answers.

Sian-Lee-SA commented 1 year ago

Thanks and thanks for your patience!