[SOLVED] How to use input_boolean.prev_light_state

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?

I’m intrigued by this. Where did you get the prev_light_state from?

I saw it in these two posts:

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:

  1. Light A is in State X
  2. Human Trips Motion Sensor A
  3. Light A changes to State Y for 2 mins
  4. After 2 mins, Light A changes back to State X

Have you considered what would happen if State X is on?

Human trips motion sensor, light changes to off for 2 minutes, then changes back to on.

If you know that State X must always be off then there’s no need to keep a record of it in an input_boolean.

  1. Human Trips Motion Sensor A
  2. Light A changes to on for 2 mins
  3. After 2 mins, Light A changes back to off.

Right. That’s the whole point. I’m looking for a way to store the state, whatever it may be, so I can make a change and then go back to what it was.

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?

Sorry gang, I’m not explaining well. Let me a try a different way. Here are multiple scenarios that should be the result of our work together.

Scenario 1

  1. Light A is currently Green at Brightness 55%
  2. Human Trips Motion Sensor A
  3. Light A changes to White at Brightness 100% for 2 mins
  4. After 2 mins, Light A changes back to Green at Brightness 55%

Scenario 2

  1. Light A is currently OFF
  2. Human Trips Motion Sensor A
  3. Light A changes to White at Brightness 100% for 2 mins
  4. After 2 mins, Light A changes back to OFF

Scenario 3

  1. Light A is currently Blue at Brightness 20%
  2. Human Trips Motion Sensor A
  3. Light A changes to White at Brightness 100% for 2 mins
  4. After 2 mins, Light A changes back to Blue at Brightness 20%

Scenario 4

  1. Light A is currently White at Brightness 100%
  2. Human Trips Motion Sensor A
  3. Light A changes to White at Brightness 100% for 2 mins
  4. After 2 mins, Light A changes back to White at Brightness 100%

Does that make more sense?

You’ll more than just an input_boolean to store a light’s current state, brightness, and color …

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:

  1. save the various states to the above created entities
  2. change the light to white 100%
  3. wait 2 min
  4. 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?

@123 looks like I need to speed up or leave it to you, I seem to be writing my answers while you’re posting yours :stuck_out_tongue:

Don’t count on me because I’m rapidly losing interest in this thread. It’s taken almost 10 posts just to clarify what the user wants to accomplish.

We all need to start somewhere and English is not everyone’s native language…

Thanks, @lolouk44.

So, what would a formula like this look like? I guess I was hoping to see examples of how one would set this up.

Answer to your question: We could simply have a condition that it doesn’t run if the light is 100% white. That would solve all of those.

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.

1 Like

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.

Good luck!

@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.

1 Like

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.