Shelly and friendly name

Hi!

I’m new to HA and shelly devices.

I installed shelly switches, conefcted them to WiFi, static IP (192.168.0.201 and 202)
I set Device name in shelly web configuration to “stik201” and “stik202”.
Both have a button (not a switch) connected to them, so I set them to “momentary” type.

Then I started HA.
Configuraton - Devices: I see both stik201 and stik202
Dashboard: I have a card and both switches on the card and it works, I can torn them on/off
In device settings in HA I have
Name: stik201
Entity ID: switch.stik201
and
Name: stik202
Entity ID: light.stik202 # this one is dimmer

Then I try to create automation, so when I do a long press on “stik201Ž” it turns off both.
I start to create automation in UI, then switch to yaml view.

And it works, IF I use:

trigger:
  - platform: event
    event_type: shelly.click
    event_data:
      device: shelly1-A4CF12F48A96
      channel: 1
      click_type: long
condition: []
action:
  - type: turn_off
    device_id: b6a4f2e720f88661fe7a189525e7566e
    entity_id: switch.stikalo201
    domain: switch
  - type: turn_off
    device_id: 4bf1a07157f48a597316321c22f7c130
    entity_id: light.stikalo202
    domain: light
mode: single

But it is not very “friendly” to have names like “4bf1a07157f48a597316321c22f7c130” and “shelly1-A4CF12F48A96”

I tried with

trigger:
  - platform: event
    event_type: shelly.click
    event_data:
      device_id: b6a4f2e720f88661fe7a189525e7566e

But it does not work with:

trigger:
  - platform: event
    event_type: shelly.click
    event_data:
      device_id: switch.stik201

Is there a way to write this automations with “stik201” and “stik202” names?

Did I forgot to define something?

Thx Jure

What about this?

trigger:
  - platform: event
    event_type: shelly.click
    event_data:
      entity_id: switch.stik201

You can listen to events in the developer tools to see what data is actually sent.

Nope, “switch.stik201” does not work.

If I listen to events, I get:

{
    "event_type": "shelly.click",
    "data": {
        "device_id": "b6a4f2e720f88661fe7a189525e7566e",
        "device": "shelly1-A4CF12F48A96",
        "channel": 1,
        "click_type": "long"
    },
    "origin": "LOCAL",
    "time_fired": "2021-02-10T06:40:48.428140+00:00",
    "context": {
        "id": "20f3bcb4ead5e1af41c7843ed578f7b7",
        "parent_id": null,
        "user_id": null
    }
}

That is also where I got device name in the first place.
Automation also works both with

        "device_id": "b6a4f2e720f88661fe7a189525e7566e",

and

        "device": "shelly1-A4CF12F48A96",

but this is very unpractical, to sniff for every device for its ID.

Is “A4CF12F48A96” MAC address of shelly?
Can it change with FW update to shelly?

I have not had any firmware updates change that hex code

It looks like you are suck with the long alphanumeric identifiers. There’s nothing else in the event data.

Can I define some “global” variables in HA?
Something like

var myShellyName = "b6a4f2e720f88661fe7a189525e7566e"

So I could use it like:

trigger:
  - platform: event
    event_type: shelly.click
    event_data:
      device_id: "{{ myShellyName }}"

You could use secrets

device_id: !secret my_shelly_name

Otherwise there’s this