You might have read an article on my home's sump pump and how I monitor it with Home Assistant. I was asked by the service company (who comes and does an annual inspection of the system) "How often does the pump run?" and I said "Well I'm not sure because it's pretty quiet, but I know it's running" and I showed them the history page within Home Assistant and showing all of the times the TP-Link Energy Monitoring Switch picked up a wattage from the primary pump.

Wouldn't it be nice if I could just give them a printout each year of every time the pump ran? Home Assistant knows this information already right?

Home Assistant's File Integration

More specifically the Notify File component

Using the Notify File component Home Assistant can create a log file of just about anything you want! Let's see how to use it to log when my sump pump runs. Because we're using Home Assistant, we can also include other details such as weather conditions. Was it raining hard outside and the pump was continually activating? Or was it a sunny day and the float switch finally activated after collecting water over a longer period?

Let's Set it up!

notify:
  - name: sumplog
    platform: file
    filename: sumplog.txt
    timestamp: true

When Home Assistant starts, it will create a file called sumplog.txt in its root directory (where the configuration is stored. With Home Assistant Core this is usually /home/homeassistant/.homeassistant. It will also add timestamps to each entry automatically.

Ok, now what?

Now we can add an action to the existing automation or script or set one up to add entries to our new log file. Since I have an automation set up to notify me when the sump pump turns on, let's add it to that one as it will use the same trigger:

automation:
  alias: SumpPump Running
  trigger:
    platform: numeric_state
    entity_id: sensor.smartplug_1_current_consumption
    above: 2
  action:
    - service: notify.iOSMobileApp
      data:
        message: "Sump Pump is running"
    - service: notify.sumplog
      data:
        message: "Sump Pump Event | Watts: {{ states('sensor.smartplug_1_current_consumption') }} | Wx Conditions: {{ states('weather.hourly') }} | Temp: {{ state_attr('weather.hourly','temperature') }}F | Humid: {{ state_attr('weather.hourly','humidity') }}| Wind Speed MPH: {{ state_attr('weather.hourly','wind_speed') }}"

You can see that we are calling the service notify.sumplog which was created after configuring our integration. The message data is being sent to the service is a template that outputs a string with the sensor details we want (in my case, the current weather conditions). This renders like this:

Sump Pump Event | Watts: 0.0 | Wx Conditions: cloudy | Temp: 69F | Humid: 87| Wind Speed MPH: 5

Now we wait for the trigger of this automation to occur and then we can take a look at our sumplog.txt file. Here are the first few rows of mine:

Home Assistant notifications (Log started: 2021-07-11T09:21:33.464368+00:00)
--------------------------------------------------------------------------------
2021-07-11T09:21:33.464368+00:00 Sump Pump Event | Watts: 11.39 | Wx Conditions: rainy | Temp: 65F | Humid: 90| Wind Speed MPH: 11
2021-07-11T10:08:03.943357+00:00 Sump Pump Event | Watts: 695.81 | Wx Conditions: rainy | Temp: 65F | Humid: 90| Wind Speed MPH: 11
2021-07-11T11:44:03.948858+00:00 Sump Pump Event | Watts: 316.93 | Wx Conditions: cloudy | Temp: 64F | Humid: 93| Wind Speed MPH: 10
2021-07-11T15:13:34.338237+00:00 Sump Pump Event | Watts: 684.48 | Wx Conditions: cloudy | Temp: 66F | Humid: 90| Wind Speed MPH: 9
2021-07-11T19:15:05.035246+00:00 Sump Pump Event | Watts: 609.26 | Wx Conditions: cloudy | Temp: 79F | Humid: 52| Wind Speed MPH: 16
2021-07-11T21:34:06.997111+00:00 Sump Pump Event | Watts: 658.42 | Wx Conditions: cloudy | Temp: 81F | Humid: 44| Wind Speed MPH: 17
2021-07-11T22:48:05.938416+00:00 Sump Pump Event | Watts: 665.11 | Wx Conditions: cloudy | Temp: 81F | Humid: 45| Wind Speed MPH: 15
2021-07-12T04:27:06.649790+00:00 Sump Pump Event | Watts: 683.5 | Wx Conditions: partlycloudy | Temp: 71F | Humid: 66| Wind Speed MPH: 6
2021-07-12T20:28:08.565041+00:00 Sump Pump Event | Watts: 661.1 | Wx Conditions: partlycloudy | Temp: 81F | Humid: 45| Wind Speed MPH: 6
2021-07-13T02:07:39.370084+00:00 Sump Pump Event | Watts: 674.78 | Wx Conditions: partlycloudy | Temp: 79F | Humid: 52| Wind Speed MPH: 5
2021-07-13T21:55:02.333515+00:00 Sump Pump Event | Watts: 656.34 | Wx Conditions: cloudy | Temp: 86F | Humid: 53| Wind Speed MPH: 9
2021-07-15T02:25:35.702504+00:00 Sump Pump Event | Watts: 665.82 | Wx Conditions: cloudy | Temp: 79F | Humid: 82| Wind Speed MPH: 10
2021-07-16T04:29:10.798305+00:00 Sump Pump Event | Watts: 682.13 | Wx Conditions: cloudy | Temp: 79F | Humid: 60| Wind Speed MPH: 6
2021-07-17T19:32:46.601587+00:00 Sump Pump Event | Watts: 610.22 | Wx Conditions: cloudy | Temp: 80F | Humid: 71| Wind Speed MPH: 9
2021-07-19T14:48:23.743142+00:00 Sump Pump Event | Watts: 589.51 | Wx Conditions: sunny | Temp: 65F | Humid: 90| Wind Speed MPH: 3

What I like here is the correlation of the Sump Pump running events with the weather conditions. When the pumps are working overtime during a rainstorm event, you can see these just as well as the entry at the end where the pump ran when it was sunny out.

What else?

I have two other file logs set up: one for my APRS beacons and another for keeping track of my Subaru Forester's telematics. I set this one up before I went on a cross-country road trip so I could keep a log of the values that Home Assistant gets from the Subaru Starlink integration.

notify:
  - name: sumplog
    platform: file
    filename: sumplog.txt
    timestamp: true
  - name: subarulog
    platform: file
    filename: subarulog.txt
    timestamp: true

The Subaru Starlink Integration updates its entities the moment you turn your car's engine off. The car uplinks its latest data to the service and the Home Assistant Integration updates relatively quickly after that.  So I simply use the state change for the odometer entity to trigger the logging.

automation subarulog:
  alias: Subaru logging to file
  trigger:
    - platform: state
      entity_id:
        - sensor.forester_odometer

  action:
    - service: notify.subarulog
      data:
        message: "Forester Log | Odometer: {{ states.sensor.forester_odometer.state }} | Battery: {{ states.sensor.forester_12v_battery_voltage.state }} | AvgFuelConsumption: {{ states.sensor.forester_avg_fuel_consumption.state }} | range: {{ states.sensor.forester_range.state }}  | tpfl: {{ states.sensor.forester_tire_pressure_fl.state }} | tpfr: {{ states.sensor.forester_tire_pressure_fr.state }} | tprl: {{ states.sensor.forester_tire_pressure_rl.state }} | tprr: {{ states.sensor.forester_tire_pressure_rr.state }}"

The output of this template will show up in your log file as follows:

"Forester Log | Odometer: 11628.3 | Battery: 12.5 | AvgFuelConsumption: 28.0 | range: 229.9  | tpfl: 32.0 | tpfr: 32.0 | tprl: 31.0 | tprr: 32.0"

The Odometer reading serves as a good reference point, at least for my road trip. It was interesting to see the range value change as I stopped along my route to fill up.

Home Assistant notifications (Log started: 2021-05-30T01:02:10.820242+00:00)
--------------------------------------------------------------------------------
2021-05-30T01:02:10.820242+00:00 Forester Log | Odometer: 6065.8 | Battery: 12.5 | AvgFuelConsumption: 26.4 | range: 379.7  | tpfl: 35.0 | tpfr: 35.0 | tprl: 34.0 | tprr: 35.0
2021-05-30T01:32:10.704920+00:00 Forester Log | Odometer: 6075.8 | Battery: 12.6 | AvgFuelConsumption: 26.4 | range: 369.7  | tpfl: 36.0 | tpfr: 35.0 | tprl: 34.0 | tprr: 35.0
2021-05-30T12:37:26.702157+00:00 Forester Log | Odometer: 6226.1 | Battery: 12.4 | AvgFuelConsumption: 31.8 | range: 249.8  | tpfl: 35.0 | tpfr: 35.0 | tprl: 34.0 | tprr: 34.0
2021-05-30T14:52:26.781428+00:00 Forester Log | Odometer: 6367.8 | Battery: 12.5 | AvgFuelConsumption: 31.8 | range: 349.8  | tpfl: 36.0 | tpfr: 35.0 | tprl: 35.0 | tprr: 35.0
2021-05-30T18:32:34.763159+00:00 Forester Log | Odometer: 6561.7 | Battery: 12.5 | AvgFuelConsumption: 31.8 | range: 229.9  | tpfl: 37.0 | tpfr: 36.0 | tprl: 35.0 | tprr: 36.0
2021-05-30T20:57:34.696549+00:00 Forester Log | Odometer: 6673.5 | Battery: 12.2 | AvgFuelConsumption: 31.8 | range: 379.7  | tpfl: 37.0 | tpfr: 36.0 | tprl: 35.0 | tprr: 36.0
2021-05-30T22:37:38.835300+00:00 Forester Log | Odometer: 6772.3 | Battery: 12.2 | AvgFuelConsumption: 31.8 | range: 289.6  | tpfl: 36.0 | tpfr: 36.0 | tprl: 35.0 | tprr: 35.0
2021-05-30T23:37:39.794867+00:00 Forester Log | Odometer: 6774.2 | Battery: 12.6 | AvgFuelConsumption: 31.8 | range: 279.6  | tpfl: 35.0 | tpfr: 35.0 | tprl: 34.0 | tprr: 35.0
2021-05-31T00:02:42.722698+00:00 Forester Log | Odometer: 6774.8 | Battery: 12.4 | AvgFuelConsumption: 31.8 | range: 279.6  | tpfl: 35.0 | tpfr: 35.0 | tprl: 34.0 | tprr: 34.0
2021-05-31T00:27:42.731205+00:00 Forester Log | Odometer: 6776.1 | Battery: 12.7 | AvgFuelConsumption: 31.8 | range: 479.7  | tpfl: 35.0 | tpfr: 35.0 | tprl: 34.0 | tprr: 34.0
2021-05-31T00:32:42.684588+00:00 Forester Log | Odometer: 6776.7 | Battery: 12.4 | AvgFuelConsumption: 31.8 | range: 479.7  | tpfl: 35.0 | tpfr: 35.0 | tprl: 34.0 | tprr: 34.0
2021-05-31T10:17:50.669382+00:00 Forester Log | Odometer: 6814.6 | Battery: 12.6 | AvgFuelConsumption: 31.4 | range: 409.5  | tpfl: 35.0 | tpfr: 34.0 | tprl: 33.0 | tprr: 34.0
2021-05-31T12:07:50.692703+00:00 Forester Log | Odometer: 6937.0 | Battery: 12.5 | AvgFuelConsumption: 31.8 | range: 319.4  | tpfl: 35.0 | tpfr: 34.0 | tprl: 34.0 | tprr: 34.0
2021-05-31T14:42:52.746017+00:00 Forester Log | Odometer: 7096.1 | Battery: 12.1 | AvgFuelConsumption: 31.8 | range: 319.4  | tpfl: 35.0 | tpfr: 35.0 | tprl: 34.0 | tprr: 35.0
2021-05-31T16:07:53.717424+00:00 Forester Log | Odometer: 7164.4 | Battery: 12.4 | AvgFuelConsumption: 31.8 | range: 289.6  | tpfl: 37.0 | tpfr: 36.0 | tprl: 35.0 | tprr: 36.0
2021-05-31T16:17:53.733553+00:00 Forester Log | Odometer: 7165.0 | Battery: 12.6 | AvgFuelConsumption: 31.8 | range: 559.9  | tpfl: 37.0 | tpfr: 36.0 | tprl: 35.0 | tprr: 36.0
2021-05-31T20:58:00.796071+00:00 Forester Log | Odometer: 7342.7 | Battery: 12.7 | AvgFuelConsumption: 31.8 | range: 279.6  | tpfl: 36.0 | tpfr: 36.0 | tprl: 35.0 | tprr: 36.0
2021-06-01T13:38:39.907715+00:00 Forester Log | Odometer: 7343.4 | Battery: 12.7 | AvgFuelConsumption: 31.4 | range: 269.7  | tpfl: 34.0 | tpfr: 34.0 | tprl: 32.0 | tprr: 33.0
2021-06-01T14:23:40.709078+00:00 Forester Log | Odometer: 7345.2 | Battery: 12.6 | AvgFuelConsumption: 31.4 | range: 249.8  | tpfl: 34.0 | tpfr: 34.0 | tprl: 33.0 | tprr: 34.0
2021-06-01T16:28:48.079741+00:00 Forester Log | Odometer: 7347.1 | Battery: 12.6 | AvgFuelConsumption: 31.4 | range: 449.9  | tpfl: 35.0 | tpfr: 35.0 | tprl: 34.0 | tprr: 35.0
2021-06-01T20:08:53.676023+00:00 Forester Log | Odometer: 7349.6 | Battery: 12.6 | AvgFuelConsumption: 31.4 | range: 429.4  | tpfl: 36.0 | tpfr: 35.0 | tprl: 35.0 | tprr: 35.0
2021-06-01T21:23:57.739777+00:00 Forester Log | Odometer: 7352.1 | Battery: 12.6 | AvgFuelConsumption: 31.4 | range: 409.5  | tpfl: 36.0 | tpfr: 35.0 | tprl: 34.0 | tprr: 35.0
2021-06-02T14:04:31.721314+00:00 Forester Log | Odometer: 7383.1 | Battery: 12.6 | AvgFuelConsumption: 30.5 | range: 359.8  | tpfl: 37.0 | tpfr: 36.0 | tprl: 35.0 | tprr: 36.0

Bonus: if you have your tire pressures coming into Home Assistant, you might as well graph them overtime with Graphana :)

Check out my other posts on Home Automation and other Smart Home technologies here!