Automating my Ikea standing desk

I have one of these fancy Ikea desks that lets you raise it up so you can use your computer whilst you’re standing.  When I first got it I used to stand up most afternoons, and I found that it helped reduce my headaches and the knots in my shoulders - it was really beneficial. But then I got lazy, and for the better part of the last 3 years I don’t think it went into the standing position once. I found myself spending hours just slobbing in my chair with terrible posture.

Then, one day after updating my home assistant, it just showed up as a detected device, and I found that I could raise and lower it via my home automation system.  Turns out that it was detected via my ESPHome Bluetooth proxies that I use for room based presence detection.

This gave me the idea to create an automation that detected if I had been sitting down at my desk for too long and force me to stand up!

The desk comes into Home Assistant as a cover device, like a blind or garage door - which I guess makes sense as it does raise and lower kind of like a window blind does.  The cover can be set to a specific position from 0, which is the lowest setting, to 100, which is the highest setting.  

I set the desk manually to the level I normally sit at, and recorded the value that it said, and did the same when it was in the standing position.  I could then use these numbers in my automations to detect if the desk was in the sitting or standing position. For my desk anything below 30 was sitting height, and anything above 50 was standing.

I’m pretty much guaranteed to be at my desk if I’m in my office, there’s really no other reason for me to come in here.  So I could use the presence sensor pointed at my desk in this automation.

I created an automation that would start a 2 hour countdown timer if the presence sensor detected presence, and the desk was in the sitting automation. I added another trigger to this automation for when the desk went from the standing position into the sitting position, in case I started the day working whilst standing and then sat down.

The desk entity stores the current position of the desk in an attribute called current_position, so I needed to use a Template Trigger for the second trigger. This is the one that I used, and it triggers when the attribute goes to a value below 30.

{{ state_attr('cover.alan_s_office_desk','current_position') < 30 }}

I also added this condition to the And If section to check that the desk is in the sitting position. This is needed because otherwise the automation would trigger any time the office presence sensor is triggered, regardless of the position the desk is in.

When the automation is triggered, and the desk is in the sitting position, the timer start action runs and starts a 2 hour countdown timer. This is a Timer entity that I created in Home Assistant’s helper section.

If the desk lifts up into the standing position again, another automation is triggered with a cancel timer action to stop the timer. This uses a similar template trigger as before, but instead checks for the position of the desk to be above 50.

I’ve added this same cancel timer action to an existing automation I had that turns off the lights and the air conditioner if I leave my office for more than ten minutes. This resets the timer if I leave the office for a long enough period.

I’ve also added a conditional mushroom template badge to the screensaver of the Android tablet dashboard I have next to my desk that shows the time remaining on my timer.  This way I can glance over and see how long I have left until the smart home will tell me to stand up.

Once the timer finishes, a final automation is triggered by the timer finished event trigger.  I had to create this complicated event type trigger manually, and I am sure there has to be a better way, but I’ve not figured it out. 

The automation checks to make sure that someone is in the office when the timer finishes, and if they are, it selects a preset on my monitor lights to start them flashing blue and yellow. 

If my keylight is on, which means I’m probably on a work video call, it waits until I turn that off, and it starts raising the desk by itself to force me to stand up using the cover set position action.

It works really well, and has helped me get back into the good habits that I was in before!  I’ve felt noticeably less stiff and have had less back and shoulder pain.  I could have also had the automation trigger some sort of voice alert on my voice assistant telling me to stand up, but I really prefer these types of visual notifications that don’t interrupt me in the middle of a conversation.

Next
Next

Home Assistant on a Sonoff NSPanel Pro