Faire une opération mathématique sur une “variable de scène”

Exactly, that occurred to me afterwards.

Strangely, the 200 status code is returned but Gladys returns an error (so no variable to reuse).

Ok, actually using braces outside of variables causes the error. I’m updating the GitHub issue.

1 Like

@lmilcent Actually the error comes from the fact that arrays in the responses were not being handled correctly, the parsing function only handled objects.

I’ve made a PR that fixes the issue:

Do you have a DEV environment to test?

In the meantime, you can use the Math.js API with a simple string instead of an array, and it works well :slight_smile:

What I observed during my tests:

  • First do a test with an expression without variables, like « 10+10 » (note: no spaces, Math.js apparently doesn’t like spaces)
  • Press « Try », which will populate the dictionary of available variables, because the request doesn’t need dependencies to test the request
  • Then replace the expression with the correct expression you want with the desired variables. Do not press Try, the variables are not available.
  • You can test running the scene with the « Start » button at the top of the scene

It works like that for me :slight_smile:

That’s the method I tried afterwards. But on my end, it doesn’t work on the current version of Gladys.

I don’t really

Ah yes, there was another bug actually: attributes that are returned as « null » were crashing the variable generation :smiley: So we have to wait for the fix.

Ok, I was talking more about a dev environment (like on your laptop, so you can test PRs)

Well, never mind, I’ll test extensively myself with the Math.js API and it will go into the next Gladys release (not the one you’ll see today)

I had started to set one up, but the issue was with the Zigbee service. Without an adapter, I couldn’t use it with the data from my database (to run tests on real data).
Would there be a trick to simulate an adapter, not run Zigbee2MQTT but still be able to

It depends on what you want to test — indeed, to test PRs (pull requests) related to Zigbee2mqtt, that won’t be easy. But to test things related to the core, you don’t need services. I often use a local MQTT service to test: I send values to a local mosquitto (I use https://mqttx.app/), I make myself a small dashboard, and that’s enough to test most core developments!

If you ever want to test with your DB (database), so it doesn’t impact your prod (production), you need to disable everything related to Gladys Plus so it doesn’t connect in place of your prod.

In general, what I do when I want to load a user’s DB is: before starting Gladys, I empty the table t_variable which stores all the credentials for all the services, and that way I’m sure that launching a test instance won’t contact the user’s real services (calendars, Gladys Plus, etc…).

Thanks for the info! I wouldn’t have thought of that.

Z2m supports TCP via ser2net, I’ll look into it soon. I don’t know if @spenceur has tested it.

This makes the dongle available over the network.

1 Like

That’s promising!

Hello @VonOx, would this z2m solution via ser2net to make the dongle available over the network be compatible with WSL? Because WSL doesn’t recognize USB ports…
Another question: can a sensor be paired with multiple z2m dongles (e.g., Sonoff)?

As mentioned above, I haven’t tested it yet, but I think so.

Zigbee devices are paired to a dongle. It’s exclusive.

1 Like

Another solution we’ve often discussed is being able to connect to a remote MQTT from the Z2M integration; that would allow connecting to a Z2M on a remote Pi and seeing how it behaves on a dev version of Gladys.

@lmilcent For your information I made progress on this today regarding your bug with the HTTP request to Mathjs, it wasn’t simple because I had to change the format used by the front-end for variables to handle arrays, while remaining compatible with the existing setup and the different « consumers » of these variables: the ‹ message › block and the ‹ continue only if › block.

I’ve pushed the latest version to my PR, I’ll pick it up again on Monday (It’s 7pm here :

1 Like

Thank you and have a great weekend, enjoy!

1 Like

FYI, I merged the PR that fixes the bug with the Math.js API; it will be part of the next Gladys release!

1 Like

Great, thanks :slight_smile:
I will be able to create a scene that uses a kind of averaging calculation, while waiting for Gladys to support it.

Use case

  1. Alert me if my fridge warms up:
    Retrieve the value from my fridge sensor every 30 minutes for 2 hours and alert me if the average of those values is above a threshold.

  2. (in summer only) Alert me when I air my apartment, but it starts to warm up:
    If the average of the temperatures in my living room and dining room is close to, equal to, or greater than the outside temperature, remind me to close the windows.

Tested and approved (https://gladys-new-device-name.netlify.app/)!

![image|427x134](upload

3 Likes

[quote=« lmilcent, post:38, topic:7030 »]
Tested and approved

2 Likes

Absolutely :slight_smile:
No need for a development environment on the user’s side!

1 Like