Newbie automation help please

Im looking to make an automation that when i trigger with a button it will continuously check state of door sensor, if closed turn lights red when state of door sensor changes it will change lights to green then end automation. Can someone point me in right direction

What is the entity of the button? Is it a real button that you have integrated into HA, or a button on the dashboard?

What are the entities for your door sensor, and the details for your lights? Can you already control the colour of your lights?

Your process isn’t completely clear. When you press the button, please describe the sequence of events you want to happen if the door is closed at that time; and if it is open at that time.

That’s not best practice for automations. I’d write this with the button operating a Toggle helper (input_boolean, like an internal switch). The automation would then trigger off any change in the door state, with the Toggle as a condition of continuing with the action. Answer the questions above and I’ll put something together.

Sorry i was unclear in my description, The button i plan to use is a Tradfri Button from Ikea already intergrated into HA the door sensor is an Agara door sensor and the light is a Wled lightstrip.

We have alot of bathroom traffic at my home and i wanted to make a system for when someone is in the bathroom i can use the button to turn the wled red (in my room) while the bathroom is occupied and to monitor the state of the door sensor untill the bathroom no longer occupied then light should turn green to notify me, then the automation should stop as i will no longer need the green light. Thank you for your help

I meant “how do they appear in HA as entities?”. Without that, or details of timings (e.g. When do you press the button? Is it inside the bathroom or outside? How long do you want the green light on for?), I’ll just have to answer conceptually.

Making a lot of assumptions, I’d do this with two automations:

First one:

  • Trigger off button press
  • Condition to check that light is not red (optional)
  • Action to turn light on as red

Second one:

  • Trigger off door opening
  • Condition to check that light is red
  • Action to turn light on as green, wait a time, then turn it off.

They could certainly be combined into two, but without knowing fine details, it’s safer as two. Get them working and post the YAML for each, and we can combine them if you really wanted to.