Just getting my feet wet and trying to get to grips with configuration.yaml…
I have a number of radio controlled switches (integrated into power sockets) that I turn on and off using a Raspberry Pi equipped with a 433 MHz radio. This happens on a different Pi than the one runnung Home Assistant (which runs on a HA Yellow).
To make a long story short, I can trigger the switches (on or off) using shell commands or by calling (local) URLs (e.g. via curl). The status of each switch is stored in a txt-file on the RPi.
I’ve used the information in this post:
to trigger my remote scripts and control the lights that are connected to the radio-controlled switches.
I’d like to read back the switches ‘state’ from the above-mentioned txt files (one per switch), so that HA “knows” when a light is on or off… The tip shared here:
… could be the solution. But the solution described there is for local files…
Can anyone point me in the right direction to integrate two (local) scripts that turn a switch on and off again as well as a third local script that reads the text file and puts these three bits into a single switch card on the “Overview”?
The reason I’d like to do this is that it is possible that the lights get turned on or off outside of HA (e.g. via an iOS shortcut) and then HA doesn’t realize that the state of a specific lamp has changed…
I have a few WiFi controlled switches (Develo/Tasmota/MQTT) that work fine - these report their state back to HA when switched externally - I’m trying to replicate this behavior.
That’s the problem with 433 RF - no feedback. You can make the switch ‘optimistic’ which means that ha optimistically believes the state is properly switched, rather than knowing it is switched via some feedback loop. But there is always the problem of some other device switching it. Which is why people hide their heat pump it remotes from the family, or make the switching via iOS go via HA.
That is understood, which is why I programmed my own tracking on the RPi. I also understand that my method merely tracks what the last issued command was (on or off), but not if the light is actually on or off. But it’s been working well with a bookmarked (on my iOS home screen), locally hosted, web page or the iOS shortcuts and a bunch of hacked together python scripts that automate certain lights depending on the read-out of a light sensor connected to the Pi or certain times of day, etc.
The system has worked reliably for years now and while I’m keen on upgrading to HA to get a more unified experience, I don’t want to replace hardware that is still in excellent working condition.
So, my question is: Is there a way to read the text file (one per 433-switch, which contains either a 1 or a 0) and have that drive the state of the switch in the HA dashboard?
My impression is that this should be doable, but I just don’t have the yaml-chops to make it happen…
Thanks for this, but the article seems to be focused on HA-installations that use Docker. The Home Assistant Yellow I’m using runs ‘natively’ on the RPi CM4, I believe.
I guess I will have to mess around with the ‘command line sensor’ some more. I’m confident that I can read the file using the cat command (since each file has a single character in it). But where I’m sure I will stumble is what to DO with that information, once I have it…