Simple automation unable to change switch state

sockettimed

alias: fridgeWakesUpFromUnknown
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.sockettimed
    for:
      hours: 0
      minutes: 0
      seconds: 1
    from: unknown
condition: []
action:
  - service: automation.turn_on
    metadata: {}
    data: {}
    target:
      entity_id:
        - automation.fridgeon
        - automation.fridgeoff
    enabled: false
  - service: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: switch.sockettimed
mode: single

Switch sockettimed changes state from unknown to off . Automation gets triggered and action should turn on the sockettimed state but it does not. Even when I try to turn it manually on in the automation UI does not work!

Turning the switch on in developers mode and also in /automations/device settings (manually) works.

I’m about to losing my temper and mind. Please save me.

Edit: The sockettime switch in integrated by localtuya

The key might be the unknown state. When is it in unknown and how do you get it in that state. triggering to or from unknown is generally not what you want to do. More likely you will want to trigger to or from on or off, or sometimes trigger on any state by leaving the to/from out completely. The 1 second is generally not necessary either.

The next problem I see is you are turning automations on. When I see that from people learning about automations they seem to think that will trigger the automation and make it do something. However what turning the automation on does is enable the automation to look for a trigger. That does not trigger it.

Im fully aware of this behaviour.

The key might be the unknown state. When is it in unknown and how do you get it in that state.

For testing purposes I’ve triggered unknown state via developer tools.

Sockettimer switch is a device connected to an inkbird controller. Sometimes the inkbird controller turns it’s socket off (which sockettimer is connected to) thus sockettimer goes offline and changes it’s state to unknown.

Whenever the inkbird controller turns it’s socket on (thus sockettimer get’s activated and changes it’s state from unknown) I want to catch this state change with an automation.