#HA Homekit Scenes

1 messages · Page 1 of 1 (latest)

inland scarab
#

My goal: Trigger scenes from Homekit
My idea: Create boolean inputs that can be toggled from homekit and based on those run automations.
**My solution: **

  • Create boolean inputs and label them as "Homekit triggers"
  • Create an automation that listens to state changes
    • Filter if state change is on
    • Filter if state change happened on an entity that is part of homekit triggers
    • Flip all "Homekit triggers" off except the one that started the automation
      My question:
      Is this the best approach to this problem? Since I am fairly new to HA, I am not sure if I am overdoing it and there is an easier approach. The solution right now works, I trigger one of the inputs, others flip off. I can build automations on top of it. I would like it, if the others turned off a bit faster.
alias: Toggle all homekit triggers
description: ""
triggers:
  - trigger: event
    event_type: state_changed
    event_data: {}
conditions:
  - condition: template
    value_template: "{{ is_state(trigger.event.data.entity_id, \"on\") }}"
    alias: Check if state is on
  - condition: template
    value_template: |2-
        {{ label_entities("Homekit trigger") 
            | expand
            | selectattr("entity_id", "in", [trigger.event.data.entity_id]) 
            | list
            | count > 0 }}
    alias: Check if it is a homekit trigger
actions:
  - action: input_boolean.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: |
        {{ label_entities("Homekit trigger") 
          | expand
          | rejectattr('entity_id', 'in', [trigger.event.data.entity_id]) 
          | map(attribute='entity_id') 
          | list }}
    enabled: true
    alias: Toggle off all homekit triggers except the last one that got triggered
mode: single
#

Using a single automation like this would allow me to just add new scenes easily as I don't have to worry about toggling them on and off.

wispy prawn
#

There's no such thing as turning a scene off. Can't you just expose the scenes directly to HomeKit?

#

I'm not following what all the complexity is for

inland scarab
#

I am not a fan of the scenes in home assistant, they feel less powerful than automations. Triggering these booleans allows me to trigger automations afterwards.

wispy prawn
#

Then just use scripts instead of scenes and expose those.

#

Then you can do whatever else you want in the script

#

Scenes are indeed very limited, and you can do anything in a script that you can do in a scene

#

It seems like you're adding a bunch of complexity without any benefit

inland scarab
#

The goal would be to have scenes toggleable, as I have a small living space. I plan to have 4 different scenes right now:

  • Home
  • Away
  • Bed time
  • Sleep time

My logic would be, that if I trigger one, the other 3 would be disabled. I also would like it to be easy to add more scenes that follow this logic.

The complexity I have set up allows me to add a new scene right now by:

  • Creating a boolean input
  • Adding the label "Homekit trigger" to it

It would be exposed to homekit, and I could toggle the new scene on and the rest would automatically be toggled off.

wispy prawn
#

There is no 'toggle off' for scenes or scripts, they're just activated

#

Seems like you're just repeating your initial post

inland scarab
#

That's why I have these boolean inputs that act as triggers for my automation scripts. When I refer to "Scene" in reality it's just a boolean input that I switch on.

wispy prawn
#

I get that. It seems to add nothing

#

Scenes aren't toggled

#

If you want to activate a different one, just activate it. They don't have a state that needs to be managed

inland scarab
#

It keeps track of which scene is active, allowing me to do automation on top of it (e.g. if sleep is active, turn on lights in the morning in the living room if there is motion). If I add a TV scene, I wouldn't want the lights to come on if there is motion detected (even if it is 7 in the morning)

wispy prawn
#

Then a template select seeks a better fit

#

It will have a selected option amongst a set of options and you can choose what to do when an option is selected

#

And you can expose it to HomeKit

inland scarab
#

I went down this path:

Created 2 sensors, that keep track of whenever one of the triggers get called

  sensors:
    last_homekit_trigger_toggled_on:
      friendly_name: Last homekit trigger toggled on
      value_template: >-
        {{ label_entities("Homekit trigger") | expand | sort(attribute='last_changed', reverse=true) | selectattr('state', 'match', 'on') | map(attribute='entity_id') | first }}

- platform: template
  sensors:
    last_homekit_trigger_toggled_off:
      friendly_name: Last homekit trigger toggled off
      value_template: >-
        {{ label_entities("Homekit trigger") | expand | sort(attribute='last_changed', reverse=true) | selectattr('state', 'match', 'off') | map(attribute='entity_id') | first }}```