Logging to "logbook" with a button, or is there something else I can use?

Hi everyone,

I’m trying to replace an app my wife and I use to log various activities for our dogs.

When you open the app, you have a number of buttons for different activities:

  • Bathroom trip
  • Walk
  • Food
  • Water
  • Medication
  • Treat

When you click on the activity, it asks you which dog did the activity:

  • Dog 1
  • Dog 2
  • Both

Once that’s done, it creates a log entry on the main page of the app with a timestamp, the dog’s name, and the activity.

I’m trying to figure out if it’s possible to do something like this within Home Assistant. I’ve seen the “Logbook” card, but it seems to be based on one or more entities, and I’m not certain if I can create “blank” entities, that I can use a button to update.

Definitely open to suggestions. I’ve tried searching, but I wasn’t able to find anything related to what I’m doing. Admittedly, it’s a bit of an odd request.

Thanks!

1 Like

Simplest approach could be to create multiple helpers and use its data in a service call.

  • input_select for the activities
  • input_button for your doggies ( dog1, dog2, both)

Create a Grid Card with 3 Button Cards.

Every Button Card gets a tap action with a service call:


type: button
entity: input_button.dog1
name: Dog 1
icon: mdi:dog
icon_height: 42px
show_name: true
show_icon: true
tap_action:
  action: call-service
  service: logbook.log
  service_data:
    name: Dog Diary
    message: |
      {% set time = as_timestamp(states('input_button.dog1') |timestamp_custom('%d.%m.%Y, %R Uhr', now() ) %}
      {% set dog = state_attr('input_button.dog1', 'friendly_name') %}
      {% set activity = states('input_select.dog_activities') %}
      {{ dog }}: {{ activity }} | {{ time }}
    domain: input_button
    entity_id: input_ button.dog1

Of course the above can also be done via automation.

Note that if you want to use the logbook function and you have configured the recorder integration, you have to include the entities above. And if you purge your database the logbook entries will be purged, too.

To avoid this you might take a look at File - Home Assistant

2 Likes

Thanks @pedolsky, that’s exactly what I was looking for. I’m going to play around with it this weekend. I have the recorder set up with an external database already, so I’m good to go there; but I’ll definitely look into the file option if I want to keep the history for longer than my standard retention.

Feel free to report on your progress, I’d be interested.

Had a few minutes free, so I put together a quick version for testing, with some changes:

Logbook Card

type: logbook
entities:
  - input_button.dog_1
title: Dog Log
hours_to_show: 1

Food Button

type: button
entity: input_button.dog_1
name: 'Dog 1: Food'
icon: mdi:dog
icon_height: 40px
show_name: true
show_icon: true
tap_action:
  action: call-service
  service: logbook.log
  service_data:
    name: Dog Log
    domain: input_button
    entity_id: input_button.dog_1
    message: >
      {% set dog = state_attr('input_button.dog_1', 'friendly_name') %} {{ dog
      }}: Ate some food
hold_action:
  action: none

Water Button

type: button
entity: input_button.dog_1
name: 'Dog 1: Water'
icon: mdi:dog
icon_height: 40px
show_name: true
show_icon: true
tap_action:
  action: call-service
  service: logbook.log
  service_data:
    name: Dog Log
    domain: input_button
    entity_id: input_button.dog_1
    message: >
      {% set dog = state_attr('input_button.dog_1', 'friendly_name') %} {{ dog
      }}: Drank some water
hold_action:
  action: none

I definitely want to spend more time working on it, but in terms of functionality, it’s exactly what I was looking for.

Nice!

With a little automation, you can also recreate the function of the app in principle. Instead of an input select 5 buttons and a State Filter Card /Conditional Card, which displays the Grid Card when one of the buttons is pressed.

And thanks for inspiration, I’ve been thinking about building something similar for our kitty cats for a while.

2 Likes

Fun to see others with the same use case. I landed here looking to better format the logbook myself to add history below our buttons.

For these you tap the button and it stamps the time. Feature request from my wife is a history…

3 Likes

How do you get the cards to show the time from the log?

@Hitman247m How did your logbook end up looking?

I’m thinking about doing something super similiar to what you described :slight_smile:

Sorry, I didn’t notice the notification for your message. It looks like this:

I actually stopped using it (got lazy), but clicked the buttons a few times to show you what it looks like