Customizing logbook.log sensor entry

Im using custom logbook entries to display a logbook card on a dashboard.

Im doing this through the use of an automation to log the custom entry into a template sensor which is then displayed on the dashboard in a logbook card.

Everything is working great BUT, Id really like to truncate the entry to just what is in the Automation.

The Automation:

alias: testing logbook formatting
trigger:
  - platform: state
    entity_id: switch1.test
    to: "on"
    id: switch1_test_on
action:
  - choose:
      - conditions:
          - condition: trigger
            id: switch1_test_on
        sequence:
          - service: logbook.log
            data:
              name: Switch1
              message: " was turned on from the front right hand panel"
              entity_id: sensor.switch1_logbook

The sensor template:

sensors:
  switch1_logbook:         
    value_template: ''

The card:

cards:
  - type: logbook
    entities:
      - sensor.switch1_logbook

What gets displayed in the card is:

Switch1 was turned on from the front right hand panel triggered by automation testing logbook formatting triggered by state of switch1.test

What I’d really like is to truncate all the un-needed info to the right of the message so it looks like this:

Switch1 was turned on from the front right hand panel 

Any ideas as to how to achieve this?

Perhaps a jinja template that truncates everything to the right of triggered by???

I Ive done a bit of research and .split may be a way of achieving this but my understanding of the logbook card doesnt quite work.

Ive taken a look in the states history and logbook of sensor.switch1_logbook and it is blank (obviously because of the template). It would appear that in the automation, the - service: logbook.log doesnt log anything to entity_id: sensor.switch1_logbook

However the automation data (name: message:) DOES show up in a logbook card.

Any help in how to achieve this would be appreciated.

My understanding is that this info comes automatically from the context object. It might be possible to clear it before calling logbook.log

Looking for the same thing! Have you ever found a solution for this?

@robin.thoni any clue on how the context object can be cleared?

This is what I’m using right now:

alias: "[Notification] Porte Garage Cabanon"
description: ""
mode: single
triggers:
  - entity_id:
      - binary_sensor.shed_garage_door
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 2
    id: sensor
    trigger: state
  - entity_id:
      - input_button.shed_garage_door
    from: null
    id: button
    trigger: state
conditions: []
actions:
  - variables:
      username: >
        {%- if trigger.id == 'sensor' -%}

        None

        {%- else -%}

        {%- set user_id = trigger.to_state.context.user_id -%}

        {%- set triggered_by = (states.person |
        selectattr('attributes.user_id','==', user_id)) | list -%}

        {{ "Home Assistant" if not triggered_by else state_attr((triggered_by |
        first).entity_id, "friendly_name") }}

        {%- endif -%}
  - choose:
      - conditions:
          - condition: trigger
            id:
              - sensor
        sequence:
          - data:
              message: Porte de garage du cabanon ouverte manuellement
            action: script.send_camera_snapshots
      - conditions:
          - condition: trigger
            id:
              - button
        sequence:
          - wait_for_trigger:
              - entity_id:
                  - binary_sensor.shed_garage_door
                from: "off"
                to: "on"
                for:
                  hours: 0
                  minutes: 0
                  seconds: 0
                trigger: state
            continue_on_timeout: false
            timeout:
              hours: 0
              minutes: 0
              seconds: 10
              milliseconds: 0
          - metadata: {}
            data:
              entity_id: binary_sensor.shed_garage_door
              domain: binary_sensor
              name: >-
                {{ state_attr('binary_sensor.shed_garage_door', 'friendly_name')
                }}
              message: >
                ouverte {{ ("par " + username) if username else "manuellement
                (bouton ou bip)" }}
            action: logbook.log
          - data:
              message: >
                Porte de garage du cabanon ouverte {{ ("par " + username) if
                username else "manuellement (bouton ou bip)" }}
            action: script.send_camera_snapshots
          - delay:
              hours: 0
              minutes: 0
              seconds: 5
              milliseconds: 0

My use-case is to show in the logbook of a binary_sensor who opened the door. So, when someone clicks on the button on HA, the automation will wait a bit to see if the sensor switched from off to on (otherwise, it means it’s closing the door). Then it’ll just log using logbook.log. If the binary sensor triggers without any button action from HA, it means the door was opened using the wall switch, and there’s no (easy) way to know who it is.

Not sure it actually answers the question:

Thanks for the info but indeed it does not really answer the question as from what I can see you still have the “triggered by automation …” postfix added to the logbook message.
That is the message I intend to get rid of, as did the OP.

Following the topic. I have the same problem. I would like to cut off all the useless data from logbook and write down only the basics like:
" entity switch ON by event X" without all the other stuff