Homelab, Linux, JS & ABAP (~˘▾˘)~
 

[Home Assistant] Get friendly name of the triggering device in an automation

In an automation, you can retrieve the friendly_name of the triggering device using:

{{ trigger.to_state.attributes.friendly_name }}

Helpful if an automation can be triggered by different devices (e.g. garage door 1 or garage door 2) and you want to send a notification that explicitly names the triggering device:

  - service: notify.ALL_DEVICES
    data:
      title: Garage open!
      message: >-
        {{ trigger.to_state.attributes.friendly_name }} is open

[CAP] Invoke custom handlers when querying local entity

const cds = require('@sap/cds');

module.exports = async srv => {

     const { Objects } = srv.entities // entities from myService.cds
   
     srv.on("myAction", async req => {
        const query = SELECT.one.from(Objects).where({ id: req.data.myId })
        const srv = await cds.connect.to('myService')
        const data = await srv.run(query)
        console.log(data) 
        return data
    })

    srv.on("READ", Objects, async req => {
        console.log("Objects called")
        // Select data from db or forward query to external system
        // ...
        // return data
    })

}