Create persistent virtual sensors and group them

Just started using HA after abandoning Vera. I’m learning the vocabulary, the architecture and the best practices. Very steep learning curve, indeed.

I have successfully got z-wave (beta) up and running. Now I’m getting into automations. My first task is the thermostat. I have a z-wave Trane thermostat but I want to have a day, night and away temperature schedule. The way I had this working on Vera was to have virtual switches (home/away) and variables (Heat SP, Cool SP for each of the three states) The actual heat/cool is part of the thermostat as is fan control.

So I find an integration called sensor which looks like it would work as a variable and another called binary sensor which would work as a virtual switch. I also read about templates but it seems they get their data from other entities or from command line calls.

I suspect that I could make this work with sensor/binary sensor but I want to know it this is best practice? I come up with many questions.

Are sensor/binary sensor efficient (memory, speed etc.)?

Can these sensors be persistent across reboots?

Is there a better choice for persistent, UI (including Alexa) entered data?

If I do use sensor/binary sensor, is there a way to group my sensors as they are clearly related (single display in Lovelace ideal)?

Should I be writing this in Python (it is quite a simple automation)?

Is the climate integration more appropriate?

Note that I also need home/away for completely unrelated automations. Also, I will have other automations that have similar requirements (e.g. intensity of dimmer being configurable for a day/night intensity).

I have checked the forums and looked at docs but did not find my answers. If there is docs (or a forum post) to answer my questions, please just point me there.

There are about a dozen different ways I can think of to solve this. However, I’ll start simply.

You’ll want to use input_booleans for your binary switches and input_text for your mode variables. While you can use sensors/binary_sensors for what you want to do, inputs were pretty much made for this very thing. Alternatively, you could also build presence into your HA and use the person domain (person.you, person.your_partner, person.your_child) and avoid doing home/away in variables.

Yes and no. By setting initial values, you can keep them quasi-persistent. However, a much better approach would be to write a HA start-up automation that sets them based upon whatever variables you require them to be. So, for instance, if HA restarts at 16:00, in your HA start-up routine, you could set your mode input_text (let’s call it input_text.hvac_mode) to whatever you want it to be in the afternoon.

Yup, groups.yaml. There is no front-end editor for it (yet), but the construct of groups in YAML is super simple.

You could, but if you’re just starting out, I’d stick to what is built into HA and then once you’ve mastered that, move on to things like AppDaemon or PyScript.

Have a look at this:

1 Like

@code-in-progress many thanks!

I suppose by starting simply you have chosen a balance between simplicity, performance, expandability etc. and leaned it toward simplicity. Good thing. I still have to learn how to walk…

Actually, I couldn’t even find how to include a sensor/binary sensor. When I tried to, it doesn’t show up as an integration so maybe the docs is just showing it but it is only available internally (python?).

Where do I find docs about input_booleans and input_text?

I actually am working on presence (being an apple household makes it pretty easy). I do see how I could make home/away through this but I really meant “vacation mode” which is a bit trickier.

Ouch. Could be a serious problem. I understand your example but that would be to set the thermostat to the initial value of the stored variable. The initial value is a design-time value but I would want to set the thermostat to the last known value of the appropriate variable which may have changed minutes, days, weeks, months or years after the design. Any ideas?

Kinda figured that! Will be looking at that last. Sounds relatively straightforward. Are groups just for display purposes?

Kinda figured that, too. Sounds like excellent advice.

Yeah, coming from Vera, you’re going to have a fun time. The two systems are vastly different in many ways, so better to start someone off easy, imho. :slight_smile:

They aren’t integration in the UI. You’re going to have to YAML these. :slight_smile: But, once you do it, it’s pretty easy and straightforward.

input_select might actually be a better choice over input_text.

Vacation mode can easily be achieved with an input_boolean OR you can get fancy and have an automation that waits for you to leave more than x miles outside of your home zone and then automatically sets vacation mode. For instance, if my wife and I both go more than 200 miles away from our home zone, the house automatically goes into vacation mode. Even if we are only going for a day trip, it allows us to be gone longer and the house will still look occupied if we are gone after dark.

Nope. You can use groups in scenes, automations, scripts, etc. I use them often for home/away modes and evening/night modes where I’m setting multiple devices to the same parameters.

Just found this for input_boolean:

Restore State

If you set a valid value for initial this integration will start with state set to that value. Otherwise, it will restore the state it had prior to Home Assistant stopping.

(sorry for not figuring out the formatting everyone has been using). Looks like in the absence of an initial value it IS persistent!

1 Like

Huh, I didn’t even know that was there! That’s awesome. Guess I can finally edit my ha-startup-script. :slight_smile: