Giter Site home page Giter Site logo

Comments (10)

Buster14 avatar Buster14 commented on August 28, 2024 1

Sorry Just got back from a trip to test this again.
It still doesnt work even with parallel, so i'm not sure which part is causing this,

- id: '1650994964857'
  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.play_media
    target:
      entity_id: media_player.family_room
    data:
      media_content_id: media-source://media_source/local/Doorbell.mp3
      media_content_type: audio/mpeg
    metadata:
      title: Doorbell.mp3
      thumbnail:
      media_class: music
      children_media_class:
      navigateIds:
      - {}
      - media_content_type: app
        media_content_id: media-source://media_source
  mode: parallel

edit : nevermind after tracking down the logs, turns out the doorbell.mp3 somehow missing after reboots, its working now. i will monitor it again after few days hopefully this is the final code. thanks again

from dahuavto.

myhomeiot avatar myhomeiot commented on August 28, 2024

Hello,

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):

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

from dahuavto.

Buster14 avatar Buster14 commented on August 28, 2024

That seems to do the trick! Many thanks again @myhomeiot
Just wondering, was this change caused by home assistant or the plugin?
So next time i will think twice before updating something again.

from dahuavto.

myhomeiot avatar myhomeiot commented on August 28, 2024

Just wondering, was this change caused by home assistant or the plugin?
So next time i will think twice before updating something again.

This was caused by changes in Home Assistant which was introduced in release 2021.10 but until release 2022.2 it's process templates as usual and log the warning, more info about this change you can read here

Anyway it's good idea to read release notes before update and sometimes check Home Assistant log.

from dahuavto.

Buster14 avatar Buster14 commented on August 28, 2024

Hi, sorry to reopen this again. Since windows based gmpc is rather unstable, i decided to get sonos play 1. But i cant seem to get this working.
Sonos is detected and i can play audio through media player in HA. I have tried 2 codes :

id: '1640312308566'
alias: Dahua VTO
mode: queued
max: 10
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.play_media
    target:
      entity_id: media_player.family_room
    data:
      media_content_id: media-source://media_source/local/Doorbell.mp3

And the other one :

alias: Dahua VTO
mode: queued
trigger:
- platform: event
  event_type: dahua_vto
  event_data:
    Code: BackKeyLight
action:
- choose:
    - conditions: 
      - condition: template
        value_template: "{{ trigger.event.data.Data.State | int in [1, 2] }}"
      sequence:  
      - service: media_player.play_media
        target:
          entity_id: media_player.family_room
        data:
          media_content_id: media-source://media_source/local/Doorbell.mp3
          media_content_type: audio/mpeg
        metadata:
          title: Doorbell.mp3
          thumbnail: null
          media_class: music
          children_media_class: null
          navigateIds:
            - {}
            - media_content_type: app
              media_content_id: media-source://media_source
  default:
    - service: media_player.play_media
      target:
        entity_id: media_player.family_room
      data:
        media_content_id: media-source://media_source/local/Doorbell.mp3
        media_content_type: audio/mpeg

But neither is working, any thoughts?

from dahuavto.

myhomeiot avatar myhomeiot commented on August 28, 2024

Hello, you should run the media service call alone (outside from automation) and check if it's working at all, you can run automation from Home Assistant automation menu. it's will skip the trigger and will run action section:

  - service: media_player.play_media
    target:
      entity_id: media_player.family_room
    data:
      media_content_id: media-source://media_source/local/Doorbell.mp3

from dahuavto.

Buster14 avatar Buster14 commented on August 28, 2024

Thats the problem, with above 2 codes the automation doesn't show up on the GUI (even though it doesnt show up any errors), so i cannot test it directly.
I can however, run the media through media > local media > doorbell.mp3 using sonos and it plays just fine.
Any idea how to make above automation show up in the automation page?

from dahuavto.

Buster14 avatar Buster14 commented on August 28, 2024

I managed to run it on the GUI, turn out there's another automation that's preventing it from appearing :

id: '1650994964857'
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.play_media
    target:
      entity_id: media_player.family_room
    data:
      media_content_id: media-source://media_source/local/Doorbell.mp3
      media_content_type: audio/mpeg
    metadata:
      title: Doorbell.mp3
      thumbnail: null
      media_class: music
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://media_source
mode: queued

When i run automation with this, it works, but pressing the doorbell directly hasnt worked yet.. Maybe need action>choose?

When i test the condition above i got this error :

Error occurred while testing condition
template value should be a string for dictionary value @ data['value_template']. Got None

from dahuavto.

myhomeiot avatar myhomeiot commented on August 28, 2024

Latest versions of Home Assistant has automation debugger, try to use it in order to understand what happened.

You can remove mode: queued or change it to mode: parallel maybe first triggered automation stack at service call and other just waiting in the queue, more about automation modes you can read here.
You get error when you test the condition because trigger.event.data defined only when automation triggered by event from Dahua VTO.

from dahuavto.

Buster14 avatar Buster14 commented on August 28, 2024

Hi, this afternoon strangely it fails again, but i answered with my phone almost at the same time, maybe 5 secs difference,

any idea why?

dahuaerror

from dahuavto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.