Save state to text file

Hi Guys,
I’m wanting to save a sensor state to a text file and I’ve come across https://www.home-assistant.io/components/notify.file/

which outputed the below
Home Assistant notifications (Log started: 2019-03-27T13:25:35.741025+00:00)
--------------------------------------------------------------------------------
KmtyOWV-Wus

is there anyway to just have the sensor state and nothing else?

Try hass-cli.

1 Like

Hi,
First try to help in the community so lets see if i can :slight_smile:
I am using notify.file to get a sensor state.
Now i have made an rather ugly solution maybe, to empty the file from the extra added rows.

I use a bash script to “clean” the file. And after the data is used i empty it.

For me it is used to create another script for sending notifications to a lametric clock, there for it has to be specific for the next script to work.

Here is my solution:
I use this in a bash-script execution:

sed -n '3p' /NOTIFY_TO_FILE.txt | tr -d '\n'
sleep 10
> /NOTIFY_TO_FILE.txt

Hope it helps :slight_smile:

3 Likes

I use the notify-file component for this and have the file set up like this:

notify:
  - platform: file
    name: sumppumplog
    filename: sumppumplog.csv
    timestamp: False

And then use this automation:

# Write Count of SumpPumpRuns per Day
- alias: Write SumpPumpCount per Day
  trigger:
    platform: time
    at: '23:59:45'
  action:
    service: notify.sumppumplog
    data_template:
      message: >
        {{ now().strftime('%d/%m/%Y') }}, {{ states.sensor.sumppump_runtime_count.state }}

After the first run I manually edited the header so that I can read the csv properly as a table; the sutomation only adds info at the bottom and leave the previous entrie s unchanged.

12 Likes

Thank you this is really helpful

1 Like

I too found this quite helpful, thanks!

Same here, very helpful thanks!

I know it’s been a while since your post but just wanted to thank you for your solution re. the notify-file component. This is just what I needed.
As a side note to Synology users I believe that you have to stop/start the Home Assistant for it to reload the configuration file (took me a while to figure out!)

1 Like