Creating an own Log History Viewer - Question

Hey there! Newbie here
I’m searching for some ideas about a Project that I’m thinking about in the last weeks, but unfortunately I can’t find a start point and searched through google and this forum here to get it started but without success. maybe someone can help me:

I want to create an own log history viewer for specific sensors/lights that I want to keep an eye on. this viewer should work on my mac but also on my android phone. my idea is to have a kind of txt file or terminal that updates everytime a sensor value updates (or a light in home assistant turned on or off) - and can be easily opened to see all the new updates, like a stream of sensor data.

I have the influxdb add-on installed on hassio and it works great with grafana to visualize some sensor data, maybe that could be a starting point to grab all the sensor datas from the influxdb database, but I don´t know what would be the next step to export this data and updates regularly - any ideas how to realize that?

example picture:

Another approach would be to use MQTT Statestream, and have your apps receive MQTT messages.

Although I don’t really see why the output from grafana isn’t sufficient. It seems an awful lot of work just to see some text rather than a graph.

As another option based on your original question, you could use the File Notification component and an automation to send events to that file. E.g.:

notify:
  - platform: file
    name: mylog
    filename: mylog.txt
    timestamp: True

automation:
  - alias: Write events of interest to mylog
    trigger:
      platform: state
      entity_id:
        - sensor.SENSOR1
        - light.LIGHT1
    action:
      service: notify.mylog
      data_template:
        message: >
          {{ trigger.to_state.name }} changed to {{ trigger.to_state.state }}

You can list as many entity_id’s as you like. And, of course, you can make the message more appropriate for each type of entity/event with additional templating.

4 Likes

thank you @pnbruckner! Never heard about this File Notification before. I´ve already used this txt log function on my mac with an app called Übersicht, where you can create little Widgets for the desktop. My Widget loads the txt file with the last 40 sensor updates and reloads the file regularly:

Is it possible to edit the timestamp in notify? My Timestamp (see attachment) is quite long, I just need a short version with day and time.

Does anybody else use Übersicht? Just curious if its possible to create a widget and grab sensor data directly via curl. in their documentation it seems possible but I don´t know which command to use for that

Yes. Just turn the default timestamp off and then add to the message:

notify:
  - platform: file
    name: mylog
    filename: mylog.txt
    timestamp: False

automation:
  - alias: Write events of interest to mylog
    trigger:
      platform: state
      entity_id:
        - sensor.SENSOR1
        - light.LIGHT1
    action:
      service: notify.mylog
      data_template:
        message: >
          {{ now().strftime('%a %X') }} {{ trigger.to_state.name }} changed to {{ trigger.to_state.state }}
1 Like

That works, thanks!

This is exactly what I was looking for, thanks!
But I’m really having trouble with the part I quoted above. First of all, I’m using the automation editor, which updates the automations.yaml file. So right off the bat, the dashes and spacing don’t line up.

I think I can get around that, but the whole data_template: and message: parts just don’t seem to “take,” whether I type them into the automation editor or copy-and-paste them into the automations.yaml file directly.

If I paste these sections in to the yaml file they are ignored by the editor, and if I paste them into the editor it puts a red box around it indicating an error. I’ve tried messing around with things like removing the continuation “>” after message and putting it all on one line, single quotes, double quotes and just about every other way I found in other automation examples.

I’m sure this is a really stupid newbie question, and I tried reading all the documentation and as many examples as I could find, over and over, but I’m still drawing a blank.

Sorry, I don’t use the automation editor, so I have no idea how you could make this work in that context, other than making message:

"{{ trigger.to_state.name }} changed to {{ trigger.to_state.state }}"
1 Like

Thank you for the quick reply! That was it!!

Oddly enough, as one last gasp after I posted here, I had tried it with single quotes, and left it that way while waiting for a reply. When I came back just now and found your answer, my log file had already been merrily updating since I’d left.

For anyone landing here trying to do the same, here’s what I put in configuration.yaml, just ahead of the lines with the “!include” statements:

notify:
  - platform: file
    name: mylog
    filename: mylog.txt
    timestamp: True

In the automations.yaml file, I put the following:

- id: my_unique_id
  alias: Boiler Burner
  trigger:
  - entity_id: binary_sensor.visonic_mct_340_e_0b1243b6_1_1280
    platform: state
  action:
  - data_template:
      message: '{{ trigger.to_state.name }} changed to {{ trigger.to_state.state }}'
    service: notify.mylog

Sure enough, I have a “mylog.txt” file in the configuration folder which contains entries like this:

Home Assistant notifications (Log started: 2019-04-22T12:22:01.526905+00:00)
--------------------------------------------------------------------------------
2019-04-22T12:22:01.527134+00:00 Visonic Boiler Burner changed to on
2019-04-22T12:28:49.476516+00:00 Visonic Boiler Burner changed to off

For context, “binary_sensor.visonic_mct_340_e_0b1243b6_1_1280” is the name of a Visonic MCT-340 E door/temperature sensor. I removed the reed switch which senses the door open/close and soldered in a pair of wires to a relay controlled by the power to the burner on my boiler in my home heating system.

The goal is to find out how often and for how long the boiler is firing. This is different from how long and how often the thermostats are calling for heat, since the boiler cycles between a high limit and low limit, whether the heat is on or off.