How to turn on the smart socket when restoring power

I have a question about the Aubess smart switch.

When power is lost/restored to the switch, I would like it not to restore the previous state, but to switch to the “on” state.
I tried the “Power-on behavior” property, for some reason only the value ‘off’ works, but ‘on’ does not.

Will there be any tips? Or maybe write some kind of automation so that when power is restored, it turns on the outlet.

If possible, can you throw off the sample code?

PS: I use a smart switch to turn on the light. When switching to the manual switch, you need the light to turn on, and it restores the past state of “off” and the light does not light up

It is problem related to poor implementation of switch firmware. This works on most smart switches (i.e. my Xiaomi Mi power plug ZigBee EU ZNCZ04LM)

Just use an automation triggered by state from Unavailable.

1 Like

Can you tell me in more detail? I’m just a beginner, I want to figure it out

Automations are under settings, go have a play.

Read the docs as always especially the ones about automations.

An automation has a trigger, a condition if you want one and an action.

What you need is trigger - state from Unavailable and action - call service - turn switch on - select your switch.

It really is very easy, but you won’t learn if you don’t have a try.

And please read the docs that’s what they are there for.

I wrote this code. But this code doesn’t work for some reason.
This code is triggered only 1 time when restarting Home Assistance
What is my mistake?

# Loads default set of integrations. Do not remove. TEST

# Load frontend themes from the themes folder
  themes: !include_dir_merge_named themes
  - platform: template
        friendly_name: "Power loss"
        device_class: power
        value_template: "{{ is_state('switch.0xa4c138c4856a9f2a', 'unavailable') }}"

  - alias: "Turn on the smart socket after power is restored"
      - platform: state
        entity_id: binary_sensor.power_loss
        from: 'on'
        to: 'off'
      - service: switch.turn_on
        entity_id: switch.0xa4c138c4856a9f2a 

script: !include scripts.yaml
scene: !include scenes.yaml

Tested it.
My code works, but not always. I need to bring my code to mind

Try something like this, you don’t need a binary sensor that is just complicating things. And this can be easily created in the gui.

description: "any name you want"
mode: single
  - platform: state
      - your switch
    from: unavailable
condition: []
  - service: switch.turn_on
    data: {}
      entity_id: your switch

I figured out the problem of the switch.
The ‘Power-on behavior’ status switches to the ‘on’ state only if the power supply to the device has not been on for more than 5 seconds. Otherwise it won’t work.
It turns out that the script is not needed here.
Thank you all