#MQTT Payload contains issue

1 messages · Page 1 of 1 (latest)

dapper dock
#

Hey. I have an MQTT payload that I want to filer to contain certain words within that payload.
THe problem is, the conditional logic put in the value template seems to get ignored. All posts to this topic get always fired. How do I filter MQTT payloads to contain keywords?

Example payload:

{"type":"Motion","trigger":"On", "memo": "person:86%"}

In Developer Tools, I can run this template that returns true/false successfully. I am trying to write this template so I can reuse and have potentially mulitple keywords.

{% set memo = (my_test_json.memo | lower) %}
{% set keywords = ['person'] %} 
{{ keywords | select('in', memo) | list | length > 0 }}

When I set it up as an action :

alias: AI Person at Gate
description: ""
triggers:
  - trigger: mqtt
    topic: blue_iris/ai/CCCGate
    value_template: >
      {% set memo = (trigger.payload_json.memo | lower) %} {% set keywords =
      ['person'] %} {{ keywords | select('in', memo) | list | length > 0 }}
  - trigger: mqtt
    topic: blue_iris/ai/CCCPtz
    value_template: >
      {% set memo = (trigger.payload_json.memo | lower) %} {% set keywords =
      ['person'] %} {{ keywords | select('in', memo) | list | length > 0 }}
conditions: []
actions:
  - action: counter.increment
    metadata: {}
    data: {}
    target:
      entity_id: counter.bi_person_at_gate
  - delay:
      hours: 1
      minutes: 0
      seconds: 0
      milliseconds: 0
  - action: counter.decrement
    metadata: {}
    data: {}
    target:
      entity_id: counter.bi_person_at_gate
mode: parallel
max: 250
#

I am sort of wondering if the value template is the entire wrong thing to use to filter the mqtt, donno

mild abyss
#

That's not what value_template does there

#

It's to determine what to match against payload:

#

Use a condition

dapper dock
#

Can I use the result of the value_template to extract the true/false and then use that in the condition? Thanks for the response!

mild abyss
#

There is no true/false there

dapper dock
#

Oh huh. The Developer Tools (with that example) give a true or false so I am probably misunderstanding something about that. THe length > 0 I was trying to generate the true/false with

mild abyss
#

But yes, you could filter the value of memo to remove the percentage and then use payload: 'person'

#

I see what you mean

#

I guess?

dapper dock
#

Using a condition was the right answer, this is what I ended up with that seems to work