#HA is automatically removing quotes

1 messages · Page 1 of 1 (latest)

vital kelp
#

I have the following code that I want to save in an automation:

triggers:
  - event_type: zha_event
    event_data:
      command: "move_with_on_off"
    trigger: event```

And HA is automatically changing it to `command: move_with_on_off` but this breaks my automation. How do I work around this?
desert ridge
#

That doesn’t make any sense that it would break your automation. What’s the error message?

vital kelp
#

It just doesn't trigger anymore. But my other automation that has command: "on" triggers correctly

desert ridge
#

If you edit it in YAML, try wrapping it single quotes and see if that helps.

#

Hmmm, are you sure that event is still being passed?

#

Like, if you listen to the event in dev tools > events, do you see that actual event?

vital kelp
#

No wait never mind

#

When I change "on" to on, HA automatically puts it back to "on" after I click on save

#

What in the lord

desert ridge
#

lol that’s how the formatter works in the backend when you save an automation in the UI. It gets… interesting.

vital kelp
#

Where can I edit it in the backend?

#

Because this is really annoying, it changes my script without me wanting it to

desert ridge
#

If it’s an automation, edit automations.yaml. If it’s a script, it’ll be scripts.yaml.

#

Hard core mode enabled. lol Just note that if you open it in the UI, it’ll reformat again.

vital kelp
#
- id: '1730497282918'
  description: ''
  triggers:
  - event_type: zha_event
    event_data:
      command: "move_with_on_off"
    trigger: event
#

This is my script in the file browser addon

#
event_type: zha_event
data:
  device_ieee: 60:a4:23:ff:fe:65:a1:38
  unique_id: 60:a4:23:ff:fe:65:a1:38:1:0x0008
  device_id: e6ee87cbd9fdf50f2d238ab03461a25d
  endpoint_id: 1
  cluster_id: 8
  command: move_with_on_off
  args:
    - 0
    - 50
  params:
    move_mode: 0
    rate: 50
origin: LOCAL
time_fired: "2024-11-01T22:11:44.815880+00:00"
context:
  id: 01JBMWHM1FXXENTB8XQX8QX0FF
  parent_id: null
  user_id: null
#

And this is the event

#

But it's just not triggering

#

With or without quotes

flint pasture
#

Why do you think it matters if it has quotes or not?

#

It shouldn't matter AFAIK.

#

"on" is wrapped in quotes because it has special meaning in yaml syntax (it's interpreted as a boolean)

vital kelp
#

Even though the trigger matches the event

desert ridge
#

I still wonder if the event data is really what it should be. Like I said, watch the event in dev tools and make sure it’s actually passing that data.

flint pasture
#

on is special. That doesn't apply to move_with_on_off

vital kelp
flint pasture
#

These are identical in yaml:
command: move_with_on_off
command: "move_with_on_off"

vital kelp
#

Thanks for the explanation, that's so odd that the automation isn't working then

#

The trigger event is matching the event fired by zha_event

flint pasture
#

FYI I just tried this (I have an ikea button that also fires move_with_on_off)

#

Seems to trigger fine

#
trigger: event
event_type: zha_event
event_data:
  command: move_with_on_off
vital kelp
#

Yeah so my problem was that the unique_id changes at the end from 0x0006 to 0x0008

#

And therefore it didn't find the matching data and it errored out on the conditional statement

#

But thanks for your help!

#

If I have another question, do I post it here or do I make a new thread?

desert ridge
#

That would do it.

#

What’s the question?

vital kelp
#

So I have this list in every automation related to my Zigbee switches:

bc:33:ac:ff:fe:6d:ff:39:1:0x0006: light.silicon_labs_ezsp_gameroom bc:33:ac:ff:fe:6d:ff:39:1:0x0008: light.silicon_labs_ezsp_gameroom

There's a lot more but I only show the first two to give an easy example. Can I somehow convert this into a global list that the automations can pull data out of or do I have to input this list in every automation?

#

Because adding a new light would mean I'd have to add the light to every list in every automation that has the list

desert ridge
#

You could create a template sensor with an attribute for that. You’d still have to template it in your automations and cast it to a list, but that’s how I’d do it.

vital kelp
#

Can the template sensor be made in the GUI or do I have to go back into the config files for that?

#

Trying to set it up right now but it's not going too well 😂

desert ridge
#

For an attributes sensor, it’d have to be in YAML. Sensor states only support 255 characters. But, it’s pretty easy to do.

#

Hold on and I can give you something.

vital kelp
#

ChatGPT gave me this, but it doesn't work (though it gives me some information on what is the right direction)

template:
  - sensor:
      - name: "Light Mappings"
        state: >
          {
            "bc:33:ac:ff:fe:6d:ff:39:1:0x0006": "light.silicon_labs_ezsp_gameroom",
            "bc:33:ac:ff:fe:6d:ff:39:1:0x0008": "light.silicon_labs_ezsp_gameroom"
          }

And then in my automation:

description: ""
triggers:
  - event_type: zha_event
    event_data:
      command: "on"
    trigger: event
conditions:
  - condition: template
    value_template: "{{ target is not none }}"
actions:
  - target:
      entity_id: "{{ target }}"
    action: light.turn_on
variables:
  unique_id: "{{ trigger.event.data.unique_id | default }}"
  mappings: "{{ states('sensor.light_mappings') | from_json }}"
  target: "{{ mappings.get(unique_id) }}"
#

Though unfortunately this doesn't work

desert ridge
#
- template:
  sensor:
    - name: Lights List
      unique_is: lights_list
      attributes: >-
        list: [
          { "bc:33:ac:ff:fe:6d:ff:39:1:0x0006": "light.silicon_labs_ezsp_gameroom" },
          { "bc:33:ac:ff:fe:6d:ff:39:1:0x0008": "light.silicon_labs_ezsp_gameroom" }
        ]
#

Ugh... Don't use AI... it halluncinates and doesn't know recent HA things.

#

BUt, it was close.

#

But, what do you need to use a mapping like that for in the first place? zha_event shouldn't really be needed unless you are doing something kind of out of the ordinary.

vital kelp
vital kelp
#

Which was very annoying

#

So now I can make my Zigbee switches go through HA completely and have them adjust to adaptive lighting before the lights come on

desert ridge
#

Ahhhh... Adaptive lighting strikes again... lol

vital kelp
#

Hahahah

#

Will this last piece of code work with your list in my automation?

variables:
  unique_id: "{{ trigger.event.data.unique_id | default }}"
  mappings: "{{ states('sensor.light_mappings') | from_json }}"
  target: "{{ mappings.get(unique_id) }}"```
#

Gotta change the name of the list of course

desert ridge
#

No. The from_json is wrong. You want to use {{ (state_attr('sensor.light_mappings', 'list') | list)[trigger.event.data.unique_id'] }} (I think).

vital kelp
#

This errors out:

variables:
  unique_id: "{{ trigger.event.data.unique_id | default }}"
  mappings: "{{ (state_attr('sensor.light_mappings', 'list') | list)[trigger.event.data.unique_id'] }}"
  target: "{{ mappings.get(unique_id) }}"

Message malformed: invalid template (TemplateSyntaxError: unexpected char "'" at 84) for dictionary value @ data['variables']['mappings']

waxen thorn
#

Remove the single quote after trigger.event.data.unique_id