UI automation error: expected dict for dictionary value @ data['data']

I created an automation using the UI. I’m getting an error: expected dict for dictionary value @ data[‘data’] which I assume is happening right after the camera snapshot is saved successfully.

From what I’ve read on this forum, it seems as if this error occurs when something isn’t indented or spaced correctly. Since it’s generated code and I don’t really know what I’m doing yet, I’m really hoping you’ll point me to what I’m doing incorrectly.

Here’s the generated code from automations.yaml:

- id: '1692911522842'
  alias: Garage flood motion detected
  description: Actions to take when the garage floodlight has been tripped.
  trigger:
  - platform: state
    entity_id:
    - switch.garage_floodlight
    from: 'off'
    to: 'on'
  condition: []
  action:
  - if:
    - condition: time
      after: 07:30:00
      before: '21:30:00'
      weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
    then:
    - service: camera.snapshot
      data:
        filename: /config/www/tmp/FloodLightTrigger.jpg
      target:
        entity_id: camera.working2
    - service: notify.accountname_gmail_com
      data:
        title: Garage floodlight detects motion
        message: Garage floodlight detects motion
        target: [email protected] [email protected] [email protected]
        data: /config/www/tmp/FloodLightTrigger.jpg
    - service: switch.turn_on
      data: {}
      target:
        entity_id:
        - switch.garage_chime
        - switch.laundry_chime
    - delay:
        hours: 0
        minutes: 0
        seconds: 10
        milliseconds: 0
    - service: switch.turn_off
      data: {}
      target:
        entity_id:
        - switch.garage_chime
        - switch.laundry_chime
  mode: single

Your help would be GREATLY appreciated!

The trace timeline suggests there’s a problem in the second service call.

Look at the example in the documentation for the Google Mail integration.

What stands out is that the email addresses in target are presented as a YAML list and not the way you entered them (a single line with each address separated by a space).

It should be like this:

    - service: notify.accountname_gmail_com
      data:
        title: Garage floodlight detects motion
        message: Garage floodlight detects motion
        target:
          - [email protected]
          - [email protected]
          - [email protected]

In addition, your example contains this, implying it’s attempting to attach an image file to the email message.

        data: /config/www/tmp/FloodLightTrigger.jpg

I suggest you do it like this:

    - service: notify.accountname_gmail_com
      data:
        title: Garage floodlight detects motion
        message: Garage floodlight detects motion
        target:
          - [email protected]
          - [email protected]
          - [email protected]
        images:
          - /config/www/tmp/FloodLightTrigger.jpg

If the it succeeds in sending the email, but fails to include the image then it means it cannot access the file in the specified location. Either way, let me know what happens.


NOTE

If you search the community forum for ‘email attachment’ you will find examples where the images option is used to attach image files

Thank you so-o-o much @123 Taras. I was so frustrated.

Since I’m still learning how to use HA, I want to make sure what I did wrong with setting up the email from the UI. I did put each email on a different line but I didn’t put a dash before them. Is that required to do from the UI and I didn’t do that to separate each addressee? I did make your corrections in the yaml which fixed that part.

I got an error on image. Something about can’t add extra stuff to the data. So I switched back over to developer tools/services to test my email. I tried it with images and it failed. So then I went back to the documentation, (Google Mail - Home Assistant), and images is not listed as an attribute. Does this mean I can’t send pictures with Google Mail?

I switched from trying to use smtp to using Google Mail since I couldn’t get smtp to work with gmail. See (SMTP setup with gmail - errors). If I can’t send images with Google Mail I guess I’m back to trying to figure out how to fix smtp again.

Once again thank you so much for your help. I can’t tell you how frustrated I was getting.

Glad to hear that the issue with email addresses was resolved.

I was concerned that might happen. You’re right, the documentation for Google Mail doesn’t mention the images option. I borrowed that option from the SMTP integration and now I know that was a mistake.

Based on Google Mail’s documentation, and its source code here, it appears that it doesn’t support attachments of any kind.

The SMTP integration indicates it can use Google Mail but you have to follow the special instructions described here. However, based on the link you provided, perhaps those instructions are outdated.

1 Like

Thanks again @123 Taras for your feedback. I think I’ll make a new post asking if anyone is successfully emailing images with gmail and hopefully get some encouraging response.

Since our domain provider, GoDaddy, switched to exchange we haven’t been able to send any emails via that account any more and our internet provider, PTD.net doesn’t even want to talk to us about our inability to send emails from apps so we’ve been using gmail recently from our camera, website and previous home automation software. That’s why I was so surprised that I couldn’t get it working with HA.

1 Like