Use a time condition and set times or use the sun sensor - below/above horizon
Second question:
You should set a variable, e.g. input Boolean, whenever you turn it on via Alexa/switch and put that as a condition so that the turn off automation doesn’t run when you’ve manually turned on the light.
Third question:
There might not be any way around this using a xiaomi sensor. I think those sensors start sending less and less often when there’s a lot of motion to conserve battery. It might also be a bug/feature in the gateway firmware
- id: strip_motion_on
alias: Turn on strip movement
conditions:
- condition: sun
after: sunset
after_offset: "-0:30:00"
- condition: sun
before: sunrise
before_offset: "0:30:00"
trigger:
platform: state
entity_id: binary_sensor.motion_sensor_xxx
to: 'on'
action:
service: homeassistant.turn_on
entity_id: light.yeelight_strip_xxx
To avoid the strip being turned off by the movement detector (after a minute), is a little trickier.
You could deactivate the turn off automation when someone turn on the light via a button/alexa:
For the switch it’s quite easy, use the switch as a trigger, and turn on/off the automation when you are turning off/on the light.
For alexa, I’m not sure how you integrated it and how you can handle it.
I use input_boolean to indicate turning on the light by motion detection. Turning off the light automation will trigger only when input_boolean is in the right state. Example in my config