I am trying to get the command line sensor to have scan_interval= never (I have it at a very long time at the moment) and then trigger it manually. Has anyone managed to?
So basically what I want to do is shell command but get the result to be able to know if/how the command worked. Not for debug but trigger other automations based on the repsonse
A scan_interval of “never” doesn’t exist so any alternative solution will have to exclude the use of a command line sensor. I’m not sure the alternatives are “nicer”.
How about your command line sensor just reads the contents of a file? It can scan as often as it wants. Then you write a separate script outside of HomeAssistant or write a shell-command within HomeAssistant that writes its output to that file. Either way, it would only run when you want and the sensor would always report that data from the last run - even persisting across reboots.
I’ve just managed to disable polling of all command_line sensors (but it can be selective).
It’s a simple (a few strings) custom component that you only need for that workaround as you will still be using the standard (just patched) platform.
Let me know if it’s what you’re looking for.
Perfect, this is what I was looking for. Will have to try it when I have time fix any issues this kind of custom component might cause by tweaking the internals.
I’m pretty sure it does. For decoding a sensor value I’m using a command line sensor to call a python script in order to do a calculation on a value I pass it and it then passes back a return value.
The only issue I have is some initial errors when it’s called after a startup and there’s no valid data to pass it so ideally need to only conditionally call the command if there’s valid input data. Example of my code as follows:-