#MQTT & Scrypted

1 messages · Page 1 of 1 (latest)

inland swan
#

Might as well thread this since it'll probably go on for a bit

mint estuary
#

yeah

inland swan
#

MQTT & Scrypted

#

I'm not sure which "listener" part you're referring to

#

Were you already using mosquitto in HA?

mint estuary
#

so when u setup Mqtt in ha’s integrations, you have a listener and a publish option.

and then u have mosquitos broker

#

ik the broker works because I’m using ring-mqtt

inland swan
#

oh, those are just for debugging

mint estuary
#

Ohhhh I see.

inland swan
#

you can public your own MQTT message, or listen to see what's being published to HA's broker

#

in scrypted, open your camera and go to the extensions tab/section. make sure mqtt is checked

mint estuary
#

Right, it is.

inland swan
#

user/pass will be whatever mqtt user you created

#

i'm figuring out what it expects for the URL. presumably mqtt://YOUR_IP with some path after to indicate device info

mint estuary
#

yup

#

idk if this is the same when I setup ring Mqtt the url was just “Mqtt://user@pass:ip/“

#

or whatever it was

inland swan
#

so minus the user@pass: part

#

since those are their own fields in scrypted

mint estuary
#

ah yes

inland swan
#

oh duh clicking in it in scrypted even gives an example

mint estuary
#

yeah lol

inland swan
#

mqtt://XXX/scrypted/cam01/motion

#

so far i'm only getting Settings, applicationInfo, and online

#

If you're on Windows I recommend MQTT Explorer to connect to the HA broker and see everything that's being published to it

mint estuary
#

Ohh okay! I’ll give that a try rq

inland swan
#

Oh I know why I'm not getting motion. The camera itself doesn't have any kind of motion detector. My camera actually sends motion/sound events over MQTT to Scrypted

#

So once you get your camera in Scrypted publishing to HA, maybe you'll get lucky and a motion message will just pop in

mint estuary
#

lets hope

#

motionDetected = true.

inland swan
#

sweeet

mint estuary
#

oh sweet!

#

im assuming state topic will be "scrypted/cam/motion"?

inland swan
#

Whatever you tell Scrypted to use in its MQTT section

#

I do recommend making it scrypted/whatever

mint estuary
#

alright! perfect

#

lets see if this works then

inland swan
#

But if motionDetected is already a part of the MQTT message I'd personally just make it "scrypted/cam01" or whatever cam name

mint estuary
#

yeah

#

alright, so its in home assistant but the status is saying "Unavailable"

#

oh do I need the payload?

inland swan
#

Yeah, looks like you'll need "payload_on" and "payload_off" to match whatever Scrypted sends

#

The full example from the HA docs is good to reference:

# Example configuration.yaml entry
mqtt:
  binary_sensor:
    - name: "Window Contact Sensor"
      state_topic: "home-assistant/window/contact"
      payload_on: "ON"
      availability:
        - topic: "home-assistant/window/availability"
          payload_available: "online"
          payload_not_available: "offline"
      qos: 0
      device_class: opening
      value_template: "{{ value_json.state }}"
mint estuary
#

yeah thats what im currently referencing off of.

inland swan
#

I'd probably skip the availability portion and just use expire_after

mint estuary
#

for the payload since mqtt is sending it as true/false, would that replace the online/offline?

inland swan
#
mqtt:
  binary_sensor:
    - name: "Camera Motion"
      state_topic: "scrypted/camname"
      expire_after: 60
      payload_on: true
      payload_off: false
      device_class: "motion"
#

something like that

#

assuming scrypted sends motion events at least every 60s

mint estuary
#

right

inland swan
#

Oh it does have an online property

#

Which HA should automatically handle it seems: payload_available string (Optional, default: online)

mint estuary
#

right

inland swan
#

I'd start with that and see if it works

mint estuary
#

so after putting everything in, its still showing as unavailable.

inland swan
#

Post your full YAML

mint estuary
#
mqtt:
  binary_sensor:
    - name: "Bird Cam Motion Sensor"
      state_topic: "scrypted/bird-cam/motion"
      expire_after: 60
      payload_on: true
      payload_off: false
      device_class: "motion"
inland swan
#

And post the mqtt:// URL from scrypted

mint estuary
#

wdym?

inland swan
#

Where you typed in the broker URL/user/pass in scrypted

mint estuary
#

oh yes

#

yes thats all set right

inland swan
#

Paste the URL here

#

Redact the IP if you're concerned

mint estuary
#

mqtt://IP/scrypted/bird-cam/motion

#

ive been reediting some stuff

#

everything is matching

inland swan
#

Ah okay so you put the /motion in the path itself

#

So everything about that camera--motion, online state, etc.--is under the motion path

mint estuary
#

ohhhh

#

you know lemme try removing the motion

inland swan
#

So your actual payload_on with it configured how it is now should be scrypted/bird-cam/motion/motionDetected

mint estuary
#

OH

inland swan
#

Remove /motion from MQTT and change your state_topic in HA

#

scrypted/bird-cam/motionDetected

mint estuary
#

that makes a lot of sense

inland swan
#

Are you using MQTT explorer? If you click on the topic you're trying to subscribe to it'll show you the full path in the Topic section in the top right

mint estuary
#

yeah I see it

inland swan
#

So to confirm, motionDetected is an actual topic right?

mint estuary
#

yes

inland swan
#

What's its value?

mint estuary
#

"true"

inland swan
#

No curly brackets or anything? Just, verbatim, "true"?

mint estuary
#

my bad

#

motionDetected = true

inland swan
#

Interesting, I'd think it'd at least be JSON

mint estuary
#

I can see json

#

in json format its just true

inland swan
#

Eh, try it like this and see if it works:

mqtt:
  binary_sensor:
    - name: "Bird Cam Motion Sensor"
      state_topic: "scrypted/bird-cam/motionDetected"
      expire_after: 60
      payload_on: true
      payload_off: false
      device_class: "motion"
mint estuary
#

k

inland swan
#

Assuming you've updated your mqtt URL in scrypted already

#

mqtt://IP/scrypted/bird-cam

mint estuary
#

yeah

#

Okay, some progress, it changed from Unavailable to Unknown

inland swan
#

I feel like I'm missing something about how it's being published to MQTT

#

Can you paste a screenshot of MQTT Explorer with the motionDetected topic selected to imgur?

mint estuary
inland swan
#

So yeah it's literally just a value of "true"

mint estuary
#

yeah

inland swan
#

Oh wait

#

that's online

#

Where is motionDetected

#

Is it under ScryptedDevice?

mint estuary
#

wdym?

inland swan
#

Uhh might've had my own MQTT Explorer up and gotten confused for a sec nvm

mint estuary
#

o LOL

#

looking at its logs, in ha it became unavailable

inland swan
#

Which we'd expect after 60 sec the way it's configured

mint estuary
#

ohh

inland swan
#

Try using the Publish section of MQTT Explorer that you've got expanded in that screenshot. Change it to raw and send a true

#

See if HA changes state

mint estuary
#

it did not

inland swan
#

How are you reloading configuration.yaml after you change it?

mint estuary
#

the developer, check the config, then the button restart

inland swan
#

Uhh running out of ideas

#

Try putting double quotes around true and false in the yaml config

#

Maybe it's seeing them as strings instead of bools

mint estuary
#

maybe

#

I think we got it

inland swan
#

!

mint estuary
#

hm

#

weird

#

so it went to detected, then it went to unavailable, then trying to do motion again it didnt update

#

maybe was a fluke

#

sending a raw in mqtt explorer updated it

inland swan
#

Maybe remove expire_after for testing purposes

mint estuary
#

k

#

while im waiting, if I set the motion duration to 60 in scrypted, do I need the expire after?

inland swan
#

Where do you set that? I've only got one camera in scrypted and it uses MQTT for motion, so I'm not familiar with cams it supports directly

mint estuary
#

so my wyze cam has a built in motion sensor, however their api they removed access to it for third party, but for me, I enabled opencv motion detection

inland swan
#

Ah I gotcha

mint estuary
#

and it did work!

#

it went to Clear, and then motion went to detected

inland swan
#

The HA expires_after isn't for when scrypted is functioning properly--it's for detecting when scrypted dies and stops sending messages

mint estuary
#

oh?

inland swan
#

The scrypted motion duration is basically how long it will allow gaps in motion but still consider it one long motion event

#

So if you set the scrypted motion duration to 60s it won't send anything to HA as long as there's any motion at least once every 60s

#

Since no state change

#

Normally you'd set the scrypted motion duration to like 5-10s

mint estuary
#

hm.

inland swan
#

HA expire_after is harder, since HA not hearing from scrypted might be because scrypted died, or because there's just been no motion

mint estuary
#

right

#

but in my case, im going to assume its just personal preference? because its working as is.

inland swan
#

Yeah, just preference

mint estuary
#

ah okay!

inland swan
#

For some reason your scrypted isn't sending an online topic or you could use that in HA

mint estuary
#

yeah idk-

inland swan
#

For the availability settings in the MQTT sensor

mint estuary
#

Probably because im using OpenCV not pamdiff

inland swan
#

Beyond that, you could either just not use the expires_after option, or set it to something like 6-12 hrs

#

All it does is change the sensor in HA to unavailable if it doesn't hear from scrypted in that time

mint estuary
#

ah okay

#

ima just leave it alone, because im making a dummy security panel, basically all this motion sensor needs to do is work at night when im sleeping.

#

so if it catches a bird moving mid day, it dont matter imo.

inland swan
#

True, really up to you to tweak it however you like it now

#

Glad we figured it out 🎉