Help with simple lightning automation not functioning

Hi Guys and Girls!

Background
I am fairly new to HA and need some help with an automation that I just cannot get to work! :slight_smile:

I have a table light in the cellar that turns on at sun set and off at 23:30 CET. I control the table light with a Tuya on/off switch (a little puck, but I just put it on the lamp cable), hereafter “Tuya On/Off”.

In the same room I have a smart ceiling light. In my house its “Dimmable light 8”. Its controlled with normal buttons.

My automation
When I turn on “Dimmable light 8”, I want “Tuya On/Off” to turn off. And when I turn off “Dimmable light 8” after sunset, I want “Tuya On/Off” to turn on.

Why? The table lamp has a soft light and the ceiling light is fairly strong, no reason to have the table light on when the ceiling light is on.

Turn on Tuya On/Off:

alias: Belysning källare
description: ''
trigger:
  - platform: sun
    event: sunset
condition: []
action:
  - type: turn_on
    device_id: 4a3058719dfc20a56b9b58997c1b4dff
    entity_id: switch.bf78728d3b9fa444466mos
    domain: switch
mode: single

Turn off Tuya On/Off when Dimmable Light 8 is turned on:

alias: Belysning källare mod 1
description: ''
trigger:
  - platform: device
    type: turned_on
    device_id: 7752e160276fa54c96ec7f1df19fbfe2
    entity_id: light.dimmable_light_8
    domain: light
condition: []
action:
  - type: turn_off
    device_id: 4a3058719dfc20a56b9b58997c1b4dff
    entity_id: switch.bf78728d3b9fa444466mos
    domain: switch
mode: single

Turn on Tuya On/Off when Dimmable Light 8 is turned off:

alias: Belysning källare mod 2
description: ''
trigger:
  - platform: device
    type: turned_off
    device_id: 7752e160276fa54c96ec7f1df19fbfe2
    entity_id: light.dimmable_light_8
    domain: light
condition:
  - condition: time
    after: '18:30'
  - condition: time
    before: '23:30'
action:
  - type: turn_on
    device_id: 4a3058719dfc20a56b9b58997c1b4dff
    entity_id: switch.bf78728d3b9fa444466mos
    domain: switch
mode: single

What happens?
The first time Tuya On/Off turned off when I lit Dimmable Light 8. But after that it has basically not worked. I’ve not managed to get it to turn on again when I turn off Dimmable Light 8.

The odd thing is, this is how it looks under info for my automation to turn off Tuya On/Off when I turn on Dimmable Light 8:


Its Swedish for “Turned off” then “Became unavailable” and then “Turned on” – all during the same second??

And what does it mean when this is stated in regards to the Automation?

The Trace Timeline for the automation says nothing and Tuya On/Off show no change.

Anyone have any idea what this could be about??

Does it matter if mode is “single” or like “restart”?

The modes of automation doesnot have an effect, it just defines what to do when the automation is triggered during when the automation is already executing. Single would mean that the only one automation will be triggered at a time, restart will mean that the automation will restarted if it triggered again during execution. The problem could be with the conditions. I have combined all these automations into one, you can copy this to a new automation and try after turning off all the old automations.

alias: Belysning källare
description: ''
mode: single
trigger:
  - platform: sun
    event: sunset
    offset: '00:00:10'
  - platform: state
    entity_id: light.dimmable_light_8
condition: []
action:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: time
                after: '18:30:00'
                before: '23:30:00'
              - condition: state
                entity_id: light.dimmable_light_8
                state: 'off'
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.bf78728d3b9fa444466mos
      - conditions:
          - condition: state
            entity_id: light.dimmable_light_8
            state: 'on'
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.bf78728d3b9fa444466mos
      - conditions:
          - condition: and
            conditions:
              - condition: sun
                after: sunset
              - condition: time
                before: '23:30:00'
              - condition: state
                entity_id: light.dimmable_light_8
                state: 'off'
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.bf78728d3b9fa444466mos
    default: []

Please check out the entity_ids. If you have trouble understanding the automation please do ask.

Many thanks! Now it works!

One issue though, normally the manual buttons are used, by other family members. When the ceiling light (Dimmable Light 8) is turned off with the manual button it’s not registered by HA until after it turns to unavailable after a while.

  1. Can I also trigger the table light to turn on when the ceiling lamp becomes unavailable? Like have a trigger that is State to Unavailable?

  2. If so, is there anyway to work around that it takes a while for HA to notice that the ceiling has become unavailable? Like speed up how often it’s “pinged”?

A less than pretty solution might be to dim it up and down 1% every other second? But how much downside would that mean?

I had one idea, and that is if you try to communicate with the light

This can be easily done but the real issue wont be rectified that is the delay in registering manual switch operations. There should be a reason why this delay is there. What is the type of device that is connected to dimmable Light? How is it integrated to HA?

This is not advisable as the it can cause hardware problems due to sudden operations.

Dimmable light 8 is an Osram bulb with Zigbee communicating with HA (standard set up RPI4B 8GB) through a Conbee II.

With the manual buttons, I just cut the power to the bulb, and imagine that it cannot communicate to HA that it just lost all power, right? So I imagine it is up to HA to figure out that it’s not available anymore by noting that it doesn’t respond, which I imagine takes some intervals?

Since the power are cut its the cause of delay in updating and it a firmware thing and we wont be able to solve it. The easiest thing would be to turn on the light even if the dimmable is unavailable which had been done with this.

alias: Belysning källare
description: ''
mode: single
trigger:
  - platform: sun
    event: sunset
    offset: '00:00:10'
  - platform: state
    entity_id: light.dimmable_light_8
condition: []
action:
  - choose:
      - conditions:
          - condition: and
            conditions:
              - condition: time
                after: '18:30:00'
                before: '23:30:00'
              - condition: or
                conditions:
                  - condition: state
                    entity_id: light.dimmable_light_8
                    state: 'off'
                  - condition: state
                    entity_id: light.dimmable_light_8
                    state: 'unavailable'
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.bf78728d3b9fa444466mos
      - conditions:
          - condition: state
            entity_id: light.dimmable_light_8
            state: 'on'
        sequence:
          - service: switch.turn_off
            target:
              entity_id: switch.bf78728d3b9fa444466mos
      - conditions:
          - condition: and
            conditions:
              - condition: sun
                after: sunset
              - condition: time
                before: '23:30:00'
              - condition: state
                entity_id: light.dimmable_light_8
                state: 'off'
        sequence:
          - service: switch.turn_on
            target:
              entity_id: switch.bf78728d3b9fa444466mos
    default: []

If it was a wifi device we could have used a ping sensor to know if the device turned on or off.

So are you saying if we try to communicate with this device while the device is unavailable, the state is updated sooner, in that case we can call the light.turn_on when the device is in on state and light.turn_off service if the light is in of state. This wont have any effect on the working of the device but this will check the status of the light and if unavailable , the state will be updated sooner.

Please test this. First manually switch off the light. In this condition the state must not have updated in HA. During this time just call the service light.turn_on if the light is shown as on in HA or ligh,turn_off if the state is off. And check if the state is updated sooner.

1 Like