Binary chart: adding presences?

Hello

The latest version of Glasys includes the ability to display binary charts; that said, it is not possible to display a presence (therefore presumably binary) coming from the LAN manager.
Is it possible to make these presences appear? I imagine this is related to the fact that history is not managed for LAN manager objects?

Thanks to you :wink:

Z.

Hi @zedyxer,

I’ve tried on my end, and I can add presence to a chart:

Are you sure it’s not working for you?

Hello Pierre-Gilles,

Thanks already for your reply :slight_smile: I probably didn’t express myself clearly. Actually, it is possible to associate a

I’ve looked at the code and it is being logged correctly:

Are you sure you have values for the last hour?

This service sends a value « 1 » every time a device is seen; if it is not seen, no « 0 » is sent

It’s a smartphone on Wi‑Fi managing my presence. I did turn the Wi‑Fi on and off several times this morning but nothing changes on the graph. I didn’t understand your last point about there being no « 0 » sent — does that mean I need to send a 0 by another means?

No, nothing special to do, I’m just clarifying that the integration only sends a value when the device is detected; there is currently no « return to 0 » when the device is not detected.

So even if we manage to get the graph working on your side, you’ll only see a single band of color, not an alternation between presence/absence.

Are you on the latest version of Gladys? (4.47?)

I’m on 4.47 — the fact that the integration doesn’t send 0 when not detected doesn’t prevent the graph from being displayed? Because I only have 1s despite manually turning off the Wi‑Fi on the smartphone?

Indeed, I can reproduce it.

@Terdious there’s an issue with the SQL query for binary devices, when it’s a « push » type device that only sends 1s it doesn’t work, it returns nothing

@Terdious the « change_marker » in the query is still null since it doesn’t change:

I think that as a result the query returns nothing.

I think there’s a bug with the current query even for binary devices: the first value is never returned, because the query thinks the state hasn’t changed.

What do you think of a query like this:

WITH value_changes AS (
    SELECT
        created_at,
        value,
        LAG(value) OVER (ORDER BY created_at) AS prev_value
    FROM
        t_device_feature_state
    WHERE
        device_feature_id = ?
        AND created_at > ?
),
state_transitions AS (
    SELECT
        created_at,
        value
    FROM
        value_changes
    WHERE
        prev_value IS NULL OR value != prev_value
)
SELECT
    value,
    created_at
FROM
    state_transitions
ORDER BY
    created_at ASC
LIMIT ?

On this dataset:

I count 21 distinct values

The current query returns only 20 values (everything except the first one)

The query I propose does return 21 values, alternating:

1 Like

Hello,
Sorry I’ve only just seen the conversation!!

Indeed I agree (at the same time how could I judge otherwise :grinning_face:) that the 1st value is not taken into account. Too bad I didn’t see that, and I’m really sorry.

Indeed, regarding anything that never changes state except sending 1s… it can’t work.

That way I don’t really see how to resolve this point for presence (I’ve never liked this behavior anyway… there should be a timer associated to revert to 0) or for any detector that sends a single-state update.

So what do we do then? Do you have an idea in mind?

Let me know if you want me to take care of a PR.

[quote=« Terdious, post:11, topic:9135 »]
What do we do then? Do you have an idea in mind

1 Like

The full query with the end_time:

WITH value_changes AS (
    SELECT
        created_at,
        value,
        LAG(value) OVER (ORDER BY created_at) AS prev_value
    FROM
        t_device_feature_state
    WHERE
        device_feature_id = ?
        AND created_at \u003e ?
),
state_transitions AS (
    SELECT
        created_at,
        value,
        LEAD(created_at) OVER (ORDER BY created_at) AS end_time
    FROM
        value_changes
    WHERE
        prev_value IS NULL OR value != prev_value
)
SELECT
    value,
    created_at,
    end_time
FROM
    state_transitions
ORDER BY
    created_at ASC
LIMIT ?

The pull request:

2 Likes

The PR has been merged into Gladys Assistant 4.48 :

With this PR, @zedyxer you should see a continuous bar — it will only show the times when your device is detected, but not the times when your device is not detected (the infamous return-to-zero), so not very useful for now

I’ll try to look into adding that to the LAN Manager integration.

1 Like

thanks for this release, indeed the chart displays but no 0s are shown, only 1s, I’m still logged in, thanks for the work :wink:

1 Like

I just submitted a PR to add return-to-zero to the LAN Manager integration :slight_smile:

Open to feedback!

The PR:

Docker image:

gladysassistant/gladys:lan-manager-add-value-zero
2 Likes

That’s awesome, I think it’ll make life easier when it comes to attendance!

Quick bump, I’m open to feedback on this image :slight_smile:

Installed and currently being tested, many thanks!! :wink:

1 Like