DETA Grid Connect DET100HA motion sensor | fix for reset values

I have one of these (Tuya) https://grid-connect.com.au/download/det100ha/ and although it works well they have a bug in that when the power is restored, they reset the values to factory default and oddly, one of those settings is to allow the light to turn on during daylight.

Here are my two automations that fix that. I’m using https://github.com/make-all/tuya-local for the connection to Home Assistant and while that works well, the online/offline status of the sensor takes forever to update in HA so I’m using another device on the same power circuit to detect whether or not I’ve had a power cut.

Note that the values for number.deta_motion_sensor_light_level are from 2919 (dark) to 3900 (light). Values outside this range will not work.

alias: When power is restored to deck lights, force refresh of Deta motion sensor
description: >-
  The Deta motion sensor does not update in HA when the power restores,
  something to do with Local Tuya. This forces an entity to update after a power
  failure so the automation to reset to the correct settings can run.
triggers:
  - trigger: state
    entity_id:
      - sensor.deck_floodlight_restart_reason
    from: unavailable
    for:
      hours: 0
      minutes: 0
      seconds: 10
conditions: []
actions:
  - action: homeassistant.update_entity
    data:
      entity_id:
        - light.deta_motion_sensor
mode: single
alias: Set normal values for Deta motion sensor after offline
description: ""
triggers:
  - trigger: state
    entity_id:
      - light.deta_motion_sensor
    from:
      - unavailable
      - unknown
    to:
      - "off"
      - "on"
conditions: []
actions:
  - action: number.set_value
    metadata: {}
    data:
      value: "2919"
    target:
      entity_id: number.deta_motion_sensor_light_level
  - action: number.set_value
    metadata: {}
    data:
      value: "4"
    target:
      entity_id: number.deta_motion_sensor_sensitivity
  - action: number.set_value
    metadata: {}
    data:
      value: "60"
    target:
      entity_id: number.deta_motion_sensor_duration
mode: single