How to change scene while WiZ device is powered off?

I have a WiZ lamp in my appartment. It is connected to a standard light switch with which I turn it off over night. I set up home assistant to make it more cozy in the evening, and more bright again in the morning. However, when the light is physically disconnected from power with the light switch, the scene change does not go through. I do not want to have the light connected to power all night, as it seems unnecessary.

What happens now is that I turn off the light in the evening, then over night the scene switch triggers, and then I turn it back on in the morning. However, since the light was powered off in the evening, it still uses the evening scene when being turned on in the morning. How do I make it that when I reconnect the light to power in the morning, it turns on with the right scene as determined by home assistant or at least switches to the right scene after a few seconds?

There are no other automations controlling this lamp, specifically nothing in the WiZ app. In the WiZ app I set up the light to remember the last state it was in, and turn on in that state again (I disabled “WiZ click”).

Automation

State trigger from unavailable to on

Action: run scene

1 Like

Cool thanks! Is there a way to run this only once per scene change? Such that when I turn it on the first time in the morning, it changes the scene, but not on subsequent turn ons?

add this to your automation

condition:
  - condition: template
    value_template: {{ this.attributes.last_triggered is none or this.attributes.last_triggered < today_at() }}
1 Like

Nice, thanks!

Actually, this does not seem to work. My automation now looks like this:

- actions:
  - action: scene.turn_on
    data:
      transition: 0.1
    target:
      entity_id: scene.daytime
  alias: Office daytime retrigger if turned off
  conditions:
  - after: 06:00:00
    before: '18:59:00'
    condition: time
  - condition: template
    value_template: '{{ this.attributes.last_triggered is none or this.attributes.last_triggered
      < today_at("05:00:00") }}'
  mode: single
  triggers:
  - entity_id: light.office
    from: unavailable
    to: 'on'
    trigger: state

But when I try the conditions in home assistant, it fails to verify the template condition, and logs the following:

ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'this' is undefined when rendering '{{ this.attributes.last_triggered is none or this.attributes.last_triggered < today_at("05:00:00") }}'

I tried to read up on this in the docs, but as far as I understand, this should be a “state-based template”, and hence this should be available?

- actions:
  - action: scene.turn_on
    data:
      transition: 0.1
    target:
      entity_id: scene.daytime
  alias: Office daytime retrigger if turned off
  condition:
  - condition: and
    conditions:
    - after: 06:00:00
      before: '18:59:00'
      condition: time
    - condition: template
      value_template: '{{ this.attributes.last_triggered is none or this.attributes.last_triggered
      < today_at("6:01:00") }}'
  mode: single
  triggers:
  - entity_id: light.office
    from: unavailable
    to: 'on'
    trigger: state

You might try to play with < today_at(“18:59:00”)

The problem here seems to be that the template does not compile. It’s complaining that “this” does not exist. The condition never worked, even then the automation was never triggered.