Can any tell me how to use the “prev_light_state” function?
If I’m guessing correctly, I’ll be able to trigger a sensor to turn on a light and then let it go back to its previous state after a minute. If that’s true, will it continue a long transition that it may be in the middle of?
Your request is cryptic and makes it difficult for us to assist you. The post’s title is meaningless (effectively: How to <Name of an entity>). You mention using a function (prev_light_state) but no such function exists.
The examples you’ve provided use an input_boolean to store an entity’s state (i.e. it serves as a global variable). The input_boolean’s name could be anything, the examples chose prev_light_state. The value stored by the input_boolean is used, later, to restore the light’s state.
Have you tried either of the two examples? If you share the automation you’ve created then we might be in a better position to help you.
Sorry about that.
In the 2x posts, the users store the previous light state just as you said. I’m wondering if anyone can show me how to do that to effect the following:
I still don’t need to know the light’s previous state. Just use the light.toggle service.
The automation is triggered when the motion sensor is activated.
The automation’s condition confirms the 2-minute timer is not running.
The automation’s action toggles the light and starts a 2-minute timer.
When the 2-minute timer expires it toggles the light.
The condition is important. It the automation doesn’t check if the timer is already running, it will run the action every time the motion sensor activates (i.e. the undesirable behavior of toggling the light every time there’s movement detected in the room) .
If you’ve only got 2 states (on/off, not looking for colours etc), then indeed toggle is the way to go. Unless the light state=on has a specific meaning linked to a specific state of the PIR?
ok, so you want to store the state of the light before you set it to white 100% for 2 min before reverting back to previous state.
You’ll need a binary_sensor for the light’s state
Then you’ll need a separate input_number for each of brightness, red, green, blue
When the motion sensor is triggered:
save the various states to the above created entities
change the light to white 100%
wait 2 min
set the light to what it was by using above created entities
Question: what happens to the PIR’s state during these 2 min? Does it stay on for 2 min or does it go back to off? What happens when someone passes in front of the pir and then passes in front of it again after 1min 50sec?
https://www.home-assistant.io/components/input_number/ has lots of examples on how to set the input_number value and how to use it.
If you need help on how to set an input_boolean, check its doc page
I’ve already given you the logic. Try first to have a go at it, then if you have specific issues I can help again.
I have worked with many members here who are not native English speakers. It’s not a deterrent to my helping them. In this case, language is not the issue.
I like helping those who help themselves. In this case, the amount of assistance being requested by the thread’s author has outstripped my interest to provide it. Nothing more than that.
@lolouk44, Ahh! This is what I needed. Thank you! I searched the HA website and couldn’t find this page. I’ll follow the docs and post my resulting, working code for others that need it.
From my perspective (and based on my searching), it wasn’t documented and that’s why I was seeking help here. @123, it’s not helping anyone for you to complain about the OP. Just refrain from posting if you don’t want to help. It’s creating noise in the thread for others that will find this helpful like I did.
It was an explanation, not a complaint, and addressed to lolouk44 as to why I would no longer be participating.
Of the more than 37 thousand community members, two offered you assistance. The proportion of active members willing to help is a fraction of the total population. I realize you’ve only been a member here for a week and couldn’t know that. Nevertheless, it’s something to bear in mind when interacting with other members, especially those who volunteer their time to help.
Good luck with constructing the automation and we all look forward to hearing more when you’ve completed it.