I can’t find a way to have HA not show the entities as unavailable when the esp32 is powered off. I need to have the signal strength retained, and ideally have the state be off instead of unavailable.
I can’t figure out if I should be using the api or mqtt for this. I’ve tried both, but neither seems to work.
I’ve been playing around with the last will, retain, availability settings, and nothing I can find seems to work. chatgpt is next to useless for this sort of stuff, it just gives me complicated lambda functions that don’t compile.
HA will always show unavailable if it lost connection.
Having it retain the values are false values and that is why it says unavailable.
If you want to keep the values then a template sensor will work unless you reboot HA.
You create a template sensor to essentially ignore unavailable. But if HA reboots then it will become unavailable.
To solve that you would need to use an automation and input_* helpers.
Trigger the automation on a value becoming unavailable and set the value of the helper to what it was prior.
Input helpers retain their values past a HA restart so these will stay.
My use case requires having the last known value of the wifi signal strength. So yes, esphome would not work for this use case if it is automatically going to mark it as unknown.
The state is what the current value is, and the current value is unknown. Your use case is not what is normal in a smart home.
Relying on old unknown, presumed states just makes no sense.
But you can as I said before make it work.
If your existing devices are “dying out”, you might want to take a minute to consider switching protocols. When MQTTCarPresence came out HA didn’t have BT Proxies. They have made it very easy to track car presence by simply throwing a Bluetooth beacon in the glove box.
it’s not dying at all. It turns off when the car is turned off. I use this to track if the car is running or not to have it open my garage door when the car is on.
So what value is there in knowing the signal strength from some time in the past?
For your application, a Bluetooth proxy in your garage and a Bluetooth beacon in the car will work (the becaon needs to be powered on only when the car is on.) That works well for me controlling a garage door and a sliding gate some distance away, using the same beacons.
In my case the Bluetooth proxy is also the garage door controller, so it doesn’t even depend on HA, just runs locally in ESPHome which means it works even if HA or WiFi is down.
I don’t think this project uses ESPhome. It looks like Arduino. It would be easy in ESPhome as you would just change the will and birth topics to mismatch.
Can you recommend a good beacon? thats essentially what I’m using the esp as.
And the value is that depending on the signal strength, I can determine if the car is in the garage, in the driveway, or gone. So if the signal strength is -80 or more, and the esp is disconnected from wifi, I can safely assume the car is gone, whereas if the signal strength is -60 and the esp is disconnected, the car is in the garage.
I rolled my own using Silabs BGM modules - I had boards lying around. But you could just use an ESP32, like a C3 SuperMini, they’re cheap as chips, and ESPHome has a BLE server component that makes it easy to configure.
Ok, that makes sense, though there are a lot of variables that can affect the value. Anyway, the way you would do that is, in the BLE proxy, set up the esp32_ble_tracker to track your beacons, then use a template text sensor that updates with one of a set of values based on where you think the car is from signal strength, and stop updating that when the signal is lost. You might be able to to do that in HA instead, but it would be a lot easier in ESPHome IMO.
Anyway, BLE with an always-on proxy is the way to go. The proxy can be located close to the parking spot so the signal strength becomes a reliable indicator of (at least one) location.
but I’m not sure how to get it into HA. It sounds like I need to have another esp32 read the beacon, which I have one in my garage already, would you mind sharing the config for that part? If I can get the info into that esp32, I should be able to create a sensor that I pull into HA. Then I’ll have to figure out if I can read the ble signal strength and use that instead of the wifi signal strength.
If your in the USA then id highly recommend using BlueCharmBeacons which you can also find them on Amazon too if that's more convenient. The owner is a fellow HA enthusiast and is frequently available right here in these forums and hes excellent if you need help or have questions unlike pretty much everywhere else online!
Me personally, I use those BT beacons along with Espresence running on my esp32 boards but you could also use
Esphome Proxy as an alternative and then use Bermuda from your HA. Heres an example of some of my BT devices that i track for a variety of reasons.