#if you have it, just split it on the /

1 messages · Page 1 of 1 (latest)

sour echo
#

base mqtt topic would 'frigate/#' ... the subtopic I would be interested in is the camera triggering the mqtt stream, ex. 'frigate/camera1/[...]'

#

trying to figure out the syntax of the payload before I just start whackin at the keyboard

fossil kelp
#

yes but what are you trying to do

#

I need more details other than "I have htis topic"

#

if it's just "I have this topic" then you literally just use .split('/')[1]

sour echo
#

creating an automation that is triggered via mqtt, but I need to isolate the camera generating the mqtt string

fossil kelp
#

ok, then it would be {{ trigger.topic.split('/')[1] }}

sour echo
#

ahh ok -- not the payload_json

#

that's what I was hoping

#

thanks again petro

#

I'm sure this is wrong; but that would hopefully return true/false, yes?

value_template: ('input_boolean.frigate_' ~ {{ trigger.topic.split('/')[1] }} ~ '_override') == "on"
#

i'd need a states() in there

fossil kelp
#

you wrap the whole thing in {{ }} not just the trigger part.

sour echo
#

it'd still see the trigger, though right

fossil kelp
#

I don't follow

sour echo
#

with the trigger.topic.split('/)[1] ... the whole of the template would still pull out that value from the mqtt string

fossil kelp
#

yes

#

but I"m assuming you want to get the state? if yes, you need to use is_state()

sour echo
#

of that input boolean, yea. so i should use is state

#

ok

#

i gotcha

#

i just wasnt sure if you could nest the trigger peice into the template value

fossil kelp
#

you can't nest {{ }} in eachother, but you don't need to. The whole line is a template

sour echo
#

so,
value_template: {{ is_state('input_boolean.frigate_' ~ {{ trigger.topic.split('/')[1] }} ~ '_enabled') == "on" }} would work, then

fossil kelp
#

no, you're using is_state wrong. it's is_state('entity', 'state')

#

also, you need to wrap the whole template in quotes

#

also, your outside quotes need to be opposite your inside quotes

sour echo
#

or would i take out the 2nd set of curly brackets

#

ahh yea

fossil kelp
#

use the template editor to test

#

but you're nesting {{ }} inside {{ }}, which you don't need to do

sour echo
#

right

#

sorry .. work meeting;
gonna go with {{ is_state('input_boolean.frigate' ~ trigger.topic.split('/')[1] ~ '_enabled', 'on') }} ... as always (thanks) petro

#

I swear, if I could do like LinkedIn and endorse you for all the times you've helped me understand things ... sheesh you'd be gold

fossil kelp
#

Heh, I am on linked in

sour echo
#

can i use the same idea here with a time condition?

fossil kelp
#

What do you mean time condition

sour echo
#

eg. after: "{{states('input_datetime.frigate_'~trigger.topic.split('/')[1]~'_time_on').state}}"

#

or would it barf

fossil kelp
#

it will barf because conditions don't accept templates

sour echo
#

yeah figured

fossil kelp
#

you can make a template condition

#

but you have to template the whole check

sour echo
#

how do you mean, ... like {{ xxx and yyy }} ??

fossil kelp
#

like now between time a and b

sour echo
#

ah

#

(googles)

fossil kelp
#

post what you want the condition to be

sour echo
#

i have 2 date_times, on and off

#

1 is set to 0630, the other lets say 2100

#

the automation i am rewriting (for myself) is this:

#
 - if:
     condition:
       - condition: time
         after: input_datetime.frigate_lighting_time_on
         before: input_datetime.frigate_lighting_time_off
    then:
fossil kelp
#
condition: template
value_template: >
  {% set start = states('input_datetime.frigate_'~trigger.topic.split('/')[1]~'_time_on') | as_datetime | as_local %}
  {% set end = states('input_datetime.frigate_'~trigger.topic.split('/')[1]~'_time_off') | as_datetime | as_local %}
  {{ start <= now() <= end }}
sour echo
#

can you explain the return to me? -- start is lessthan equalto now() lessthan equalto end?

#

no 'and' operator?

#

is that a jinja thing?

fossil kelp
#

the and is implied

sour echo
#

ahh

fossil kelp
#

this is a python thing

sour echo
#

ohhh

#

ok

#

thats my vb logic showing

#

lol

#

so in writing for example, it would be the equivilent of 'start is lessthan equalto now() [and now()] lessthan equalto end'

fossil kelp
#

yep

sour echo
#

gotcha

#

well thats different

#

but cool

#

learnin new stuff this time