iharosi / homebridge-plex-webhooks

Plex Webhooks Server plugin for Homebridge
GNU Affero General Public License v3.0
48 stars 5 forks source link

Clarification Needed on Filter Ruleset Logic for Local Playback #34

Open hevalito opened 8 months ago

hevalito commented 8 months ago

Hello y'all!

I've successfully set up the homebridge-plex-webhooks plugin, and everything is working as expected, except for some confusion I'm experiencing with the filter ruleset logic.

Issue Description

I am trying to set up sensors to trigger automations only when media is played locally on my Plex TVs. For this, I have configured key-value pairs in the filter rules for events like media.play and media.resume, specifically targeting Player.local as true and Player.uuid with the respective UUIDs of my devices.

Configuration Example

Here's an example of how I've set up one of the sensors:

Observed Behavior

Despite the configuration, the logs indicate that the sensor is triggered even when the conditions don't seem to be met. For instance:

[1/3/2024, 8:59:32 PM] [PLEX] Checking filter rulesets of [Playing Locally (WHZ)] sensor:
[1/3/2024, 8:59:32 PM] [PLEX]  > filter group #1
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "media.play" at "event", found "media.resume"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "true" at "Player.local", found "false"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "UUID1" at "Player.uuid", found "ANOTHER-UUID (NOT MINE)"
[1/3/2024, 8:59:32 PM] [PLEX]  > filter group #2
[1/3/2024, 8:59:32 PM] [PLEX]  + looking for "media.resume" at "event", found "media.resume"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "true" at "Player.local", found "false"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "UUID1" at "Player.uuid", found "ANOTHER-UUID (NOT MINE)"
[1/3/2024, 8:59:32 PM] [PLEX]  > filter group #3
[1/3/2024, 8:59:32 PM] [PLEX] Checking filter rulesets of [Playing Locally (SCHZ)] sensor:
[1/3/2024, 8:59:32 PM] [PLEX]  > filter group #1
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "media.play" at "event", found "media.resume"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "true" at "Player.local", found "false"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "UUID2" at "Player.uuid", found "ANOTHER-UUID (NOT MINE)"
[1/3/2024, 8:59:32 PM] [PLEX]  > filter group #2
[1/3/2024, 8:59:32 PM] [PLEX]  + looking for "media.resume" at "event", found "media.resume"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "true" at "Player.local", found "false"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "UUID2" at "Player.uuid", found "ANOTHER-UUID (NOT MINE)"
[1/3/2024, 8:59:32 PM] [PLEX] Checking filter rulesets of [PLEX WHZ Stopped] sensor:
[1/3/2024, 8:59:32 PM] [PLEX]  > filter group #1
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "media.pause" at "event", found "media.resume"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "true" at "Player.local", found "false"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "UUID1" at "Player.uuid", found "ANOTHER-UUID (NOT MINE)"
[1/3/2024, 8:59:32 PM] [PLEX]  > filter group #2
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "media.stop" at "event", found "media.resume"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "true" at "Player.local", found "false"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "UUID1" at "Player.uuid", found "ANOTHER-UUID (NOT MINE)"
[1/3/2024, 8:59:32 PM] [PLEX] Checking filter rulesets of [PLEX SCHZ Stopped] sensor:
[1/3/2024, 8:59:32 PM] [PLEX]  > filter group #1
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "media.pause" at "event", found "media.resume"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "true" at "Player.local", found "false"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "UUID2" at "Player.uuid", found "ANOTHER-UUID (NOT MINE)"
[1/3/2024, 8:59:32 PM] [PLEX]  > filter group #2
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "media.stop" at "event", found "media.resume"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "true" at "Player.local", found "false"
[1/3/2024, 8:59:32 PM] [PLEX]  - looking for "UUID2" at "Player.uuid", found "ANOTHER-UUID (NOT MINE)"
[1/3/2024, 8:59:32 PM] [PLEX] [Playing Locally (WHZ)] is active

Question

My understanding is that all key-value pairs in at least one group of the sensor should be true for the sensor to be triggered. However, as per the logs, it seems the sensor is activated even when not all conditions are met.

Could you please help clarify how the filter ruleset logic is supposed to work in this scenario? Specifically, I'm looking to understand:

Any insights or guidance on this matter would be greatly appreciated.

Thank you!

hevalito commented 8 months ago

It also doesn't work for the other sensor, even though it should, see the log:

[1/3/2024, 9:12:36 PM] [PLEX] Checking filter rulesets of [Playing Locally (WHZ)] sensor:
[1/3/2024, 9:12:36 PM] [PLEX]  > filter group #1
[1/3/2024, 9:12:36 PM] [PLEX]  - looking for "media.play" at "event", found "media.stop"
[1/3/2024, 9:12:36 PM] [PLEX]  + looking for "true" at "Player.local", found "true"
[1/3/2024, 9:12:36 PM] [PLEX]  + looking for "UUID1" at "Player.uuid", found "UUID1"
[1/3/2024, 9:12:36 PM] [PLEX]  > filter group #2
[1/3/2024, 9:12:36 PM] [PLEX]  - looking for "media.resume" at "event", found "media.stop"
[1/3/2024, 9:12:36 PM] [PLEX]  + looking for "true" at "Player.local", found "true"
[1/3/2024, 9:12:36 PM] [PLEX]  + looking for "UUID1" at "Player.uuid", found "UUID1"
[1/3/2024, 9:12:36 PM] [PLEX]  > filter group #3
[1/3/2024, 9:12:36 PM] [PLEX] Checking filter rulesets of [Playing Locally (SCHZ)] sensor:
[1/3/2024, 9:12:36 PM] [PLEX]  > filter group #1
[1/3/2024, 9:12:36 PM] [PLEX]  - looking for "media.play" at "event", found "media.stop"
[1/3/2024, 9:12:36 PM] [PLEX]  + looking for "true" at "Player.local", found "true"
[1/3/2024, 9:12:36 PM] [PLEX]  - looking for "UUID2" at "Player.uuid", found "UUID1"
[1/3/2024, 9:12:36 PM] [PLEX]  > filter group #2
[1/3/2024, 9:12:36 PM] [PLEX]  - looking for "media.resume" at "event", found "media.stop"
[1/3/2024, 9:12:36 PM] [PLEX]  + looking for "true" at "Player.local", found "true"
[1/3/2024, 9:12:36 PM] [PLEX]  - looking for "UUID2" at "Player.uuid", found "UUID1"
[1/3/2024, 9:12:36 PM] [PLEX] Checking filter rulesets of [PLEX WHZ Stopped] sensor:
[1/3/2024, 9:12:36 PM] [PLEX]  > filter group #1
[1/3/2024, 9:12:36 PM] [PLEX]  - looking for "media.pause" at "event", found "media.stop"
[1/3/2024, 9:12:36 PM] [PLEX]  + looking for "true" at "Player.local", found "true"
[1/3/2024, 9:12:36 PM] [PLEX]  + looking for "UUID1" at "Player.uuid", found "UUID1"
[1/3/2024, 9:12:36 PM] [PLEX]  > filter group #2
[1/3/2024, 9:12:36 PM] [PLEX]  + looking for "media.stop" at "event", found "media.stop"
[1/3/2024, 9:12:36 PM] [PLEX]  + looking for "true" at "Player.local", found "true"
[1/3/2024, 9:12:36 PM] [PLEX]  + looking for "UUID1" at "Player.uuid", found "UUID1"
[1/3/2024, 9:12:36 PM] [PLEX] Checking filter rulesets of [PLEX SCHZ Stopped] sensor:
[1/3/2024, 9:12:36 PM] [PLEX]  > filter group #1
[1/3/2024, 9:12:36 PM] [PLEX]  - looking for "media.pause" at "event", found "media.stop"
[1/3/2024, 9:12:36 PM] [PLEX]  + looking for "true" at "Player.local", found "true"
[1/3/2024, 9:12:36 PM] [PLEX]  - looking for "UUID2" at "Player.uuid", found "UUID1"
[1/3/2024, 9:12:36 PM] [PLEX]  > filter group #2
[1/3/2024, 9:12:36 PM] [PLEX]  + looking for "media.stop" at "event", found "media.stop"
[1/3/2024, 9:12:36 PM] [PLEX]  + looking for "true" at "Player.local", found "true"
[1/3/2024, 9:12:36 PM] [PLEX]  - looking for "UUID2" at "Player.uuid", found "UUID1"
[1/3/2024, 9:12:36 PM] [PLEX] [Playing Locally (WHZ)] is inactive
[1/3/2024, 9:12:36 PM] [PLEX] [PLEX WHZ Stopped] is inactive

filter group #2 full matches and as far as I understand the groups are in an "OR" relation this sensor should be triggered, wouldn't it?

iharosi commented 7 months ago

Hi @hevalito! Could you please provide your config and other environment details like node version etc. It would highly help the investigation. You can find a bug ticket here which does have a template for this. Thanks.

hevalito commented 7 months ago

Hey! I didn't create a bug ticket just yet because I was unsure of wether this behavior is normal or if it indeed is a bug. Looking at the logs - do you agree this looks wrong?

iharosi commented 7 months ago

Yeah something's strange, that's why I'd like to see your config. I wouldn't want you to create a bug ticket, just use the template from there if you need it. We can start with your config in JSON format and don't forget to remove any personal data like UUID or other things.

hevalito commented 7 months ago
{
    "name": "PLEX",
    "sensors": [
        {
            "name": "Playing Locally (WHZ)",
            "filters": [
                [
                    {
                        "path": "event",
                        "operator": "===",
                        "value": "media.play"
                    },
                    {
                        "path": "Player.local",
                        "operator": "===",
                        "value": "true"
                    },
                    {
                        "path": "Player.uuid",
                        "operator": "===",
                        "value": "UUID2"
                    },
                    {
                        "operator": "==="
                    }
                ],
                [
                    {
                        "path": "event",
                        "operator": "===",
                        "value": "media.resume"
                    },
                    {
                        "path": "Player.local",
                        "operator": "===",
                        "value": "true"
                    },
                    {
                        "path": "Player.uuid",
                        "operator": "===",
                        "value": "UUID2"
                    }
                ],
                [
                    {
                        "operator": "==="
                    },
                    {
                        "operator": "==="
                    },
                    {
                        "operator": "==="
                    }
                ]
            ]
        },
        {
            "name": "Playing Locally (SCHZ)",
            "filters": [
                [
                    {
                        "path": "event",
                        "operator": "===",
                        "value": "media.play"
                    },
                    {
                        "path": "Player.local",
                        "operator": "===",
                        "value": "true"
                    },
                    {
                        "path": "Player.uuid",
                        "operator": "===",
                        "value": "UUID1"
                    }
                ],
                [
                    {
                        "path": "event",
                        "operator": "===",
                        "value": "media.resume"
                    },
                    {
                        "path": "Player.local",
                        "operator": "===",
                        "value": "true"
                    },
                    {
                        "path": "Player.uuid",
                        "operator": "===",
                        "value": "UUID1"
                    }
                ]
            ]
        },
        {
            "name": "PLEX WHZ Stopped",
            "filters": [
                [
                    {
                        "path": "event",
                        "operator": "===",
                        "value": "media.pause"
                    },
                    {
                        "path": "Player.local",
                        "operator": "===",
                        "value": "true"
                    },
                    {
                        "path": "Player.uuid",
                        "operator": "===",
                        "value": "UUID2"
                    }
                ],
                [
                    {
                        "path": "event",
                        "operator": "===",
                        "value": "media.stop"
                    },
                    {
                        "path": "Player.local",
                        "operator": "===",
                        "value": "true"
                    },
                    {
                        "path": "Player.uuid",
                        "operator": "===",
                        "value": "UUID2"
                    }
                ]
            ]
        },
        {
            "name": "PLEX SCHZ Stopped",
            "filters": [
                [
                    {
                        "path": "event",
                        "operator": "===",
                        "value": "media.pause"
                    },
                    {
                        "path": "Player.local",
                        "operator": "===",
                        "value": "true"
                    },
                    {
                        "path": "Player.uuid",
                        "operator": "===",
                        "value": "UUID1"
                    }
                ],
                [
                    {
                        "path": "event",
                        "operator": "===",
                        "value": "media.stop"
                    },
                    {
                        "path": "Player.local",
                        "operator": "===",
                        "value": "true"
                    },
                    {
                        "path": "Player.uuid",
                        "operator": "===",
                        "value": "UUID1"
                    }
                ]
            ]
        }
    ],
    "verbose": true,
    "_bridge": {
        "username": "REDACTED",
        "port": REDACTED
    },
    "platform": "PlexWebhooks"
}