I have the following problem: a reed-sensor is connected to the oil valve of my central heating. So i can receive via MQTT a "1", for oil burner is on and a "0", for oil burner is off.
Now i would like to open with every MQTT message ("1" or "0") a json file to read the values recorded so far. after that i would increment the data and write it back to the same file.
i have added some pseudocode. I hope with this flow, you have a better understanding of my problem.
What works for me is: I can create an read a json file. It is also possible to work with the data fom the file. And i can save the file with the new data.
What does not work for me: In my "calc operating time" function i have no access to the MGTT message ( "1" or "0") from my oil burner.
How can i solve my problem?
Edit: removed SourceCode, added Screenshot