Hue motion sensor + Shelly 1 Automation not working properly

Hi guys I am relatively new to home assistant and unfortunately I got stuck on solving my automation problem.

Set-up: I have a hue motion detector in the guest bathroom connected to Home assistant by zigbee2mqtt and a Shelly 1 switch (connected by MQTT) to control the lights there.
Use case: on motion detected and lux<22 the Shelly 1 should be triggered and the lights turned on. 30 seconds after no movement is detected the Shelly should turn off the lights.
The issue: all this currently works, however after the lights are turned off and immetiately a movement is detected again (I can see that the Hue detects motion) the Shelly is not switched on. I need to wait maybe 5-10 seconds (while constantly moving around) until the automations turns on the lights again.
Below is my code for the Shelly 1- MQTT set-up and the automations themselves.
Any help or advise is much appreciated.

Code in Configuration.yaml

switch:
  - platform: mqtt
    name: "Shelly1 MQTT WC"
    state_topic: "shellies/shelly1-E09806961B25/relay/0"
    command_topic: "shellies/shelly1-E09806961B25/relay/0/command"
    payload_on: "on"
    payload_off: "off"
    retain: false

Automations:

- id: '1608232750852'
  alias: Turn on light WC
  description: Turn on light when movement detected
  trigger:
  - type: motion
    platform: device
    device_id: d8a851db123811eb80e70b97e538cf42
    entity_id: binary_sensor.hue_motion_detector_occupancy
    domain: binary_sensor
  condition:
  - type: is_illuminance
    condition: device
    device_id: d8a851db123811eb80e70b97e538cf42
    entity_id: sensor.hue_motion_detector_illuminance_lux
    domain: sensor
    below: 22
  action:
  - service: homeassistant.turn_on
    entity_id: switch.shelly1_mqtt_wc
  mode: restart

- id: '1609016910773'
  alias: Turn off WC Light
  trigger:
  - type: no_motion
    platform: device
    device_id: d8a851db123811eb80e70b97e538cf42
    entity_id: binary_sensor.hue_motion_detector_occupancy
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 30
  action:
  - service: homeassistant.turn_off
    entity_id: switch.shelly1_mqtt_wc
  mode: single

Sorry, I’m not providing a solution to your problem. I’m having a similar problem with a shelly motion sensor, thar also reports luminosity values. The problem seems to be that the sensor reports the lux value at the same time it detects motion, and homeassistant is not smart enough to use those two fresh values on the automation. Instead, what happens is that it sees the latest value (probably with the light turned on) and ignored the automation on the next trigger. On that trigger the value of the lux was updated, but ignored by homeassistant, so it is not until the third trigger that the motion is triggered and the right value of the lux is taken into account.
This is a real bummer that is making most of my homeassistant automations a nightmare to deal with, and I don’t know how to fix it.