How to save actual temperature to a text file

Hello, i’m new here, just trying new stuff to work with my xiaomi temperature sensors

They are set in HA and logging the data properly.

Now i would like to save the actual temperature state to a text file and replace that value every time that it changes, so only the Temp Value would be stored in that file, nothing else. I already found some integrations but most of them just stores lots of data like history of the temperature. I just need the actual one.

Use a file “notification”

Chris has the answer. If you want a more long-winded description, I did write up a couple of things I do along a similar line:

and

The sensor has the “actual data”. Why do you need it stored in a file as well?

Nick, there are valid reasons to choose other storage options than the native HA database. Even if it were well-designed and efficient, (which I’d argue it isn’t) some people have other methods of storing and analyzing data which they prefer, for whatever reason. Maybe HA isn’t the only source of data they maintain, or maybe they’re familiar with other tools they’d rather use.

Well I know, but I find it hard to see the point of storing one piece of data that is readily available without the intervening file.

I don’t know why the OP wants it either. Here’s one possibility: Maybe they run a web server and they want to serve that file with the one updated data point in it. I’m sure I could think of other reasons if I tried.

My point is, after a career in IT, I’ve learned that we (the developers and maintainers) have to be careful not to dismiss a customer requirement until we’ve heard them out. We don’t always foresee how they’re going to use the system in their day-to-day operation. They always surprise you!

But why not just use the api?

Surely this career in IT taught you that?

I have to agree with Nick here.
Many times you get questions/requests that is equivalent to inventing the wheel four times when all you need to do is press a button.
This is a classic case of xy problem.

The question is so limited that the only answer you can give is exactly what they want but the real issue is probably something else.

As Nick say, either use the API or you could create a rest sensor to “send” the value on automation when it changes.
Or perhaps this is also wrong. The use case is perhaps something completely different.
But asking “why” is a very legitimate question in these cases.

Nobody has dismissed anything, but nobody has “listened them out either”. Nick’s question is a natural follow up on “listening” to people.

1 Like

I, for sure, definitely see a use case:

OP has no influxdb/prometheus or similar and wants to keep a simple history going further than the meager default 10 day of the recorder.

As outlined above, HA neither has nor it designed to keep long-term history.
The newer, aggregated, long-term history is a step to mitigate this, but obviously does not work if you want the actual values for whatever reasons.

1 Like

Except…

So it’s overwriting the value.
It will only show the latest value.

But I don’t think anyone dismisses the use case. But there might be a better way.

1 Like

Ah, overlooked that. Indeed makes no sense :smiley:
And my suggestion is incorrect as well, as File will append, not replace.