Well, states("") is not replaced by the sensor value in an actual shell, indeed
Why are you doing something completely different than in the OP, all of the sudden?
because i reopen the older Topic from: # jiri.prchal.
He never got an answer, but i come to the same problem on my code.
Befor i implement such code to HA, i check it in the CLI of HA first.
And when i use this command in HA direct, nothing happens. The file is still empty. → AND no Error Messages…
I try this way, because of an completely different problem I discribed here:
I had a similar problem and managed it by removing the existing file as first step with a shell_command, then use notify to export the data to a file and remove the first two lines afterwards, also with a shell_command.
Meanwhile I switched to pyscript using os.write() to export the data to a file.