I have a flic button that I have been playing with which does the follwoing:
Single Click = light.toggle
DoubleClick = light.toggle & media_player.media_play_pause
So on a double click kodi pauses and turns my light on, I pop off and do someting, come back, double click for the light to turn off and kodi to resume.
This all works well until either the light is already on or kodi is already paused. Then things go out of sync so Im looking to put a bit of logic around the toggle.
I’ve been working through some things but I just cant seem to get it.
Basically using kodis state and testing against the curent light state to decide what action to take. This way, no matter what state either is in, they wont get out of sync.
Im struggling with a) the syntaxing and b) if this is actually the right way to go about it.
The first part of the logic seems to be working but it still goes wonky.
If I pause kodi and turn the light on, the result goes back to: light.turn_on
If I then play kodi the result changes to: light.turn_off
If I then pause kodi the result changes to: light.turn_on - Getting things out of sync again.
I feel like I need another bit of logic in there somewhere to test against the state of the light at the time the button is pressed and match against the state of kodi but I have no idea how to do that!
This earlier example of yours looks like the right way to do this.
My approach:
automation:
- alias: Double Click Flic
trigger:
event_data:
button_name: flic_80e4da723c3a
click_type: double
action:
# toggle master
- service: media_player.media_play_pause
entity_id: media_player.kodi__atv
# ---> if needed, build in a delay here
# sync slave
# ... syncs playing state with lights on. you can also revert and sync with state 'paused'
- service_template: >
{% if is_state('media_player.kodi__atv', 'playing') %}
light.turn_on
{% else %}
light.turn_off
{% endif %}
entity_id: light.bedside
When I first started, I got close to something like this but with multiple if/elses for each condition which worked but really wonky and about 90 lines! Nothing as fluid as this.