How to add a time to a motion activated automation

Hi there - as above if anyone could advise me…

Im not great with setting up automations so, that being said im trying to set up a motion activated hue sensor to swtich on some kitchen under cabinet lights - also Hue based but only at sunset/ when it gets dark…

I can set up the basic motion activated part…but not sure where to add in the ability to only have it working at night/sunset…?

Thanks to anyone that has a crack at it.!

Hi, what will you be using as a night/sunset reading?

This is the action one of my automations:

if:
  - condition: state
    entity_id: light.<your entity>
    state: "off"
  - condition: state
    entity_id: sun.sun
    state: below_horizon
then:
  - data:
      transition: 2
      brightness_pct: 10
    target:
      entity_id: light.<your entity>
    action: light.turn_on
alias: IF light off & sun below horizon => light ON

For some other lights, I use luminance as a condition.
If you want to use time: this is available in the condition part but, with changing sunset/sundown, not advisable in this situation.
HTH

Hi there…dont understand any of that! - ive been using the gui to set my automations…and theyre pretty basic…!

These instructions come from the GUI
In the ‘The do’ section you pick the ‘if-then’ from blocks.

Check the documentation, it has good examples

Something else that comes to my attention.

These are your stats:

Member/using HA since 2022.
37 topics created: none of them are marked as solved! :thinking:
175 posts created.
0 appreciation towards people that help you

With these numbers I would advice you to dig a little deeper yourself if you want to get the max out of HA.

Im sure ive thanked people before on numerous occassions…must confess ive not actually marked anything as solved ( i wasnt sure i had to of course ) - we all have limitations…one of mine is scripting and coding…its just something ive never understood.

That being said i do apologise (for not marking things as solved) but, as i say within posts im more than sure ive thanked people for their input.

Ive just randomly gone back and clicked on a thread i created and pasted it below - said i solved my problen and thanked them…maybe not just check your stats…

fleskefjesRegular

Jan 2025

Router mode / firmware means the device no longer is the coordinator, but only routes traffic. Typically you use it like that if you have spots where the coverage is poor. In a Zigbee network you can only have one coordinator (think of it as a network router if that is easier) but multiple router devices (that would be switches or access points in a network perspective).

comfysofa

Jan 2025

Right - thanks. Ok. I have solved my problem…took it on the chin and rebuilt the server - got everything running now…Handy though - another question on the back of that…if it becomes a router, can it route both zigbe2mqtt and ZHA at the same time or is it one or the other…?

Another random thread of mine…

comfysofa

1

Jun 2025

ok - thats done (thanks very much) thats a new setting i didnt know of.

Edit - error is still there, but now the setting is in its rolling round each time…but thats still a handy setting though! :slight_smile:

comfysofa

1

Jun 2025

Ah - its back up…i rebooted the switch…! i do have an alternative POE switch i can plug into so ill try that tonight when i get home…

Thanks very much for your help…got me in the right direction.!

I appreciate replying to this and trying to prove me wrong.
I think this is that last reply I will make about this because I don’t want to start a discussion.

Instead: I would prefer seeing that you mark your topics as solved and get your automation running the way you like.

By marking the solution:

  • your threads can be useful to other users as well
  • it prevents someone trying to help by stepping in instead of helping others

That way you give back to this community of which all people are here in their free time.

Also, I didn’t take the time to read all your posts to see whether you did (or not) showed any appreciation.
The ‘like this post’ (heart) is a good sign to show gratitude towards each other and I’m quite sure that people use this as an easy way to evaluate.

1 Like

Post your automation’s YAML code.

To get your automation’s YAML code, display the automation in the Automation Editor then switch the display mode from Visual to YAML mode.

Copy-paste the displayed YAML code into your forum message. Select the code and then click the forum editor’s “Preformatted text” command. It will ensure your automation’s YAML code is properly formatted for display in the forum.

Hi there Taras, thanks for the reply…i have kind of found out what i want to do but, ive hit what looks like a generic error…

Message malformed: must contain at least one of below, above.

I set a blank automation, first of all added in the sunset.

Then added the sensor as the trigger

And then the device - to which gave me the above error. Googled this and it comes up in lots of instances…

You overlooked to post your automation’s YAML code, as requested with detailed instructions, so I can only guess what is the cause of the error.

It appears that you didn’t provide mandatory values.

must contain at least one of below, above.

Hi yes, i get that theres a value missing but, theres nothing in the gui that i can see where it requires it (in that all values are selected and filled)

That being said i now see what you mean about posting the YAML code in…ill see if i can recreated it (because of the error it wont let me save…)

You can switch to YAML mode and copy the YAML code without having to first save the automation.

Ok = here you go…but i cant add in the final device…i tried adding another random device but get the same error…

description: “”
mode: single
triggers:

  • trigger: sun
    event: sunset
    offset: 0
    conditions:
  • type: is_temperature
    condition: device
    device_id: f0938ac78ff6e4276cd0c542ad8924c9
    entity_id: 17d276cbe003493b4e3238c7c789ee12
    domain: sensor
    metadata:
    secondary: false
    actions:
    alias: Kitchen Light test

The code you posted is unformatted; it has lost all its indentation which is critical for YAML.

Refer to my instructions about using the Preformatted text command.

Hi there…i dont have that option from what i can see…

I just did this yesterday.

triggers:
  - trigger: state
    entity_id: binary_sensor.floodlight_sensor_garage_motion_detection
conditions:
  - condition: sun
    before: sunrise
    after: sunset
actions:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state == 'on' }}"
        sequence:
# action when the sensor transitions to "detected"
          - action: switch.turn_on
            target:
              device_id: 019b4c252faa4d891c2303ba3f125d28
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state == 'off' }}"
        sequence:
# action when the sensor transitions to "clear"
          - action: switch.turn_off
            target:
              device_id: 019b4c252faa4d891c2303ba3f125d28
mode: single

ok but im not sure what id do with that…im not great/any good with the codey stuff!

Its currently in Zigbee2MQTT (and doing a firmware upgrade which is taking forever!) i was going to switch it over to Zigbee (the other protocol) and see if that solves it…

Interesting. Click the gear icon. It may be in there. If not then put three backticks ``` on a separate line before your YAML code and then do exactly the same thing after your YAML code.

More details here: How to format your code in forum posts

1 Like

Well, this has take a strange turn…ive just created it again and its saved ( i have no idea why? or how for that matter )…within the options theres a couple of values i dont understand though…this one?


Ive just set it as that but no clue what it does…

As i say i cant fully test yet as its still light, and the firmware is still flashing on the strip light itself… (15% has taken a couple of hours so far…)