Error: In 'template' condition: UndefinedError: 'dict object' has no attribute 'State'

So i have this automation using dahua vto2202F-P-S2 and this integration, to trigger playing a doorbell from a windows machine.

id: ‘1640312308566’
alias: Dahua VTO
description: ‘’
trigger:

  • platform: event
    event_type: dahua_vto
    condition:
  • condition: template
    value_template: ‘{{ trigger.event.data.Data.State | int in [1, 2] }}’
    action:
  • service: media_player.media_play
    target:
    entity_id: media_player.gmpc
    mode: queued

I have GMPC server and GMPC player installed on my viewing station NUC machine,
The HA is installed on my main server, not the viewing station. The GMPC server’s job is to talk to HA in LAN.

On older HA version the above code would trigger doorbell.mp3 on the GMPC player.
But now it wont play at all. I’m getting this error :

Error: In ‘template’ condition: UndefinedError: ‘dict object’ has no attribute ‘State’

When trying to execute this part :

condition: template
value_template: ‘{{ trigger.event.data.Data.State | int in [1, 2] }}’

Any ideas?

Hi,
from the error message I’d say you should try this:

condition: template
value_template: ‘{{ trigger.event.data.Data["State"] | int in [1, 2] }}’

Does that work?

Hmm still throwing same error even with that code

Error: In ‘template’ condition: UndefinedError: ‘dict object’ has no attribute ‘State’

Are you sure your HA has re-read the new configuration (e.g. through restarting it)? Because the code now does to want to read an attribute named “State”. Now it wants to read the value of the key “State” in the dict trigger.event.data.Data.

Got it fixed by the plugin author,

id: '1640312308566'
alias: Dahua VTO
description: ''
trigger:
  - platform: event
    event_type: dahua_vto
    event_data:
      Code: BackKeyLight
condition:
  - condition: template
    value_template: '{{ trigger.event.data.Data.State | int in [1, 2] }}'
action:
  - service: media_player.media_play
    target:
      entity_id: media_player.gmpc
mode: queued
max: 10

You need to filter dahua_vto events with Code field equals to BackKeyLight (another event’s which comes from VTO doesn’t have field Data.State ):

1 Like