Blink lights when a call is received

Hello everyone!
I found more challenging than expected creating an automation for blinking the lights in HA
and I wanted to share my experience (and workarounds).

My goal here is to blink the lights when a call is received on the phone and restore the lights to its previous state.

For this automation we will need the following:

  • Yeelight colour bulbs
  • Tasker or some other way to link your phone with HA

Define a new input_boolean as a switch to control our automation:

input_boolean:
  call_in_progress:
    name: There is a call in progress
    icon: mdi:phone
    initial: false

Define a custom effect:

yeelight:
  custom_effects:
    - name: 'Call'
      flow_params:
        count: 0
        transitions:
          - RGBTransition: [90, 255, 36, 50, 20]
          - RGBTransition: [90, 255, 36, 50, 100]
          - RGBTransition: [90, 255, 36, 50, 20]
          - RGBTransition: [90, 255, 36, 50, 100]
          - SleepTransition:       [500]

Create an automation to be triggered when the state of the input_boolean goes to on:

- alias: 'Lights - Call In progress'
  trigger:
    - entity_id: input_boolean.call_in_progress
      platform: state
      to: 'on'
  action:
    - service: scene.create  # Needs a scene to restore switch off state
      data:
        scene_id: before
        snapshot_entities:
          - light.living_room_lights  # Change it according to you config
    - service: light.turn_on
      entity_id:
        - light.living_room_lights
      data:
        effect: 'Call'
    - wait_template: "{{ is_state('input_boolean.call_in_progress', 'off') }}"
      continue_on_timeout: 'true'
      timeout: 00:00:15
    - service: input_boolean.turn_off
      entity_id: input_boolean.call_in_progress
    - service: light.turn_on  # FIX: yeelight doesnt stop effect when scene is applied back
      entity_id:
        - light.living_room_lights
      data:
        effect: 'Stop'
    - service: scene.turn_on
      entity_id: scene.before

Now you will need to link your device to HA, in my Android setup
I use Tasker + AutoNotification plugin (optional to WhatsApp call as well)

There are some good tutorials out there about how to do this #1 #2

Once you have Tasker linked with HA, create a new Event profile Phone Ringing and
link it to a new Task which will call HA to turn on our call_in_progress input_boolean

2 Likes

Wow, I really liked your implementation. I never worked with scenes and they seem really useful.
Thanks for sharing!

I’m guessing this only works on Android and not on iOS right (since iOS is too closed)?

Nice guide!
FYI you can replace tasker with the native app now. It has a sensor of the call state of the phone (at least the android app, don’t know about the iphone app).

1 Like

Why, if I define correctly the custom effect in the configuration.yaml file, after reboot I can’t reproduce it in any way (scripts or automations)?

My yeelight are:
color4 --> YLDP13YL --> LED Bulb 1S (Color)

even in configure_ui I have no effect, I can only:
turn on
switch off
adjust brightness
change the color

thx.
Nixx

It could be you need to manually specify the device ip in order to add a custom effect, give it try, should be something like:

yeelight:
  devices:
    192.168.1.25:
      name: Living Room
  custom_effects:
    ...

More info at the bottom of this page

I do exactly that manual configuration in the yaml file.

nixx

I’ve just started using the new Android app sensor.phone_state to do this, it has idle , ringing or offhook states. I use it to mute my Alexa if its playing music and flash the lights

1 Like