royto / logbook-card

Logbook card for Home Assistant UI Lovelace
GNU General Public License v3.0
203 stars 9 forks source link

Log entries not shown in the logbook when logbook.log is called from script which was invoked from another script #94

Closed dummylabs closed 10 months ago

dummylabs commented 11 months ago

First of all, your card is amazing and I really can't live without it anymore! šŸ˜„

Describe the bug I have a simple script which I'd like to reuse in my automations and scripts to capture some custom events. It works just fine when I call it from an automation or execute it directly from Administrative tools console.

Now to the problem: if I run my script from another script, the logbook entry is being created and is visible in the Logbook panel, but it is not shown in the logbook card. From the Logbook panel perspective the only visual difference is "triggered by" statement. See screenshots below.

To Reproduce The logger script:

log:
  alias: Save message to logbook
  sequence:
    - service: logbook.log
      data:
        name: "{{ severity or 'INFO' }}"
        message: " {{ message }} "
        entity_id: input_button.dummy_logbook_entity
  mode: single

Call it from automation (event is shown in logbook-card):

alias: logme
trigger: []
condition: []
action:
  - service: script.log
    data:
      message: test from automation
mode: single

Call it from a script (event is not shown in logbook-card)

alias: test_script
sequence:
  - service: script.log
    data:
      message: test from script
mode: single

Expected behavior Logbook entries, created from a script, which was invoked from another script, are shown in the logbook-card.

Screenshots

Screen 1: both events are shown in the Logbook panel

SCR-20231224-nemh

Screen 2: only one event is shown in the logbook-card (only when the script has been invoked from automation)

SCR-20231224-neoi

Environment (please complete the following information):

Card configuration

type: custom:multiple-logbook-card
entities:
  - entity: input_button.dummy_logbook_entity
    show_history: false
    custom_logs: true
    custom_log_map:
      - name: INFO
        icon: mdi:information
        icon_color: '#00FF00'
      - name: ERROR
        icon: mdi:alert-circle
        icon_color: '#FF0000'
      - name: WARN
        icon: mdi:alert-octagram
        icon_color: '#FFFF00'
scroll: true
group_by_day: true
date_format: relative
show:
  entity_name: false
royto commented 11 months ago

Can you provide the response of the call to /api/logbook (tab network in developper tools of your browser (F12)) ?

dummylabs commented 11 months ago

I cropped two last entries which should be relevant to the issue. If you need full response please let me know:

[
    {
        "when": "2023-12-24T20:22:19.951294+00:00",
        "name": "INFO",
        "message": "test from automation",
        "domain": "input_button",
        "entity_id": "input_button.dummy_logbook_entity",
        "context_event_type": "automation_triggered",
        "context_domain": "automation",
        "context_name": "logme",
        "context_message": "triggered",
        "context_entity_id": "automation.logme",
        "context_entity_id_name": "logme"
    },
    {
        "when": "2023-12-24T20:22:25.347013+00:00",
        "name": "INFO",
        "message": "test from script",
        "domain": "input_button",
        "entity_id": "input_button.dummy_logbook_entity",
        "context_user_id": "240fb308210447b68ee94a719d7c7c77",
        "context_domain": "script",
        "context_service": "test_script",
        "context_event_type": "call_service"
    }
]
legovaer commented 10 months ago

I have been doing some trial/error with the custom logs and I also faced this issue. I have no idea if it's related to this issue, but I noticed the following error in my browser console. I'm currently on HA 2024.1.0b4

This is the stacktrace ``` logging-mixin.ts:57 Failure writing uncaught error to system log: Error: Cannot parse given Error object at Object.parse (error-stack-parser.js:35:23) at stacktrace.js:106:62 at new Promise () at fromError (stacktrace.js:105:20) at t (log-message.ts:37:31) at logging-mixin.ts:45:33 (anonymous) @ logging-mixin.ts:57 error (async) hassConnected @ logging-mixin.ts:27 hassConnected @ haptic-mixin.ts:55 hassConnected @ connection-mixin.ts:211 hassConnected @ state-display-mixin.ts:8 hassConnected @ translations-mixin.ts:120 hassConnected @ themes-mixin.ts:58 hassConnected @ auth-mixin.ts:24 value @ home-assistant.ts:34 initializeHass @ connection-mixin.ts:207 value @ home-assistant.ts:243 await in value (async) value @ home-assistant.ts:100 _$AE @ reactive-element.ts:1376 performUpdate @ reactive-element.ts:1343 scheduleUpdate @ reactive-element.ts:1261 _$Ej @ reactive-element.ts:1233 await in _$Ej (async) requestUpdate @ reactive-element.ts:1208 _$Eu @ reactive-element.ts:946 y @ reactive-element.ts:931 A @ lit-element.ts:115 F @ hass-base-mixin.ts:6 (anonymous) @ context-mixin.ts:22 (anonymous) @ logging-mixin.ts:24 (anonymous) @ panel-title-mixin.ts:12 (anonymous) @ haptic-mixin.ts:38 (anonymous) @ url-sync-mixin.ts:29 (anonymous) @ dialog-manager-mixin.ts:28 (anonymous) @ notification-mixin.ts:5 (anonymous) @ connection-mixin.ts:40 (anonymous) @ disconnect-toast-mixin.ts:18 (anonymous) @ sidebar-mixin.ts:28 (anonymous) @ action-mixin.ts:18 (anonymous) @ more-info-mixin.ts:16 (anonymous) @ state-display-mixin.ts:6 (anonymous) @ translations-mixin.ts:71 (anonymous) @ themes-mixin.ts:24 (anonymous) @ auth-mixin.ts:14 $t @ hass-element.ts:23 (anonymous) @ quick-bar-mixin.ts:23 d @ home-assistant.ts:48 E @ scoped-custom-element-registry.js:385 t @ scoped-custom-element-registry.js:236 window.CustomElementRegistry.define @ scoped-custom-element-registry.js:85 finisher @ custom-element.ts:41 runClassFinishers @ decorate.js:237 a @ decorate.js:15 (anonymous) @ home-assistant.ts:34 (anonymous) @ app.ts:10 ```