Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsonExpand - Expand json state values into individual states #910

Open
AlexanderSchulz-Siemens opened this issue Dec 21, 2023 · 5 comments

Comments

@AlexanderSchulz-Siemens

What kind of device or service would you like to see an adapter for?
Expand json state values into individual states.
E.g., Tasmota provides sensor information in the state SENSOR. There is no way to work with this data other than parsing it in scripts. Furthermore you can not configure triggers on this data because it will trigger for every change and not only for e.g. SENSOR.ENERGY.Power.

Is the device connected to the internet or only available on a local network?
local

Is an official App or Website available?
no

Is an official API including documentation available?
not applicable

Are other libraries for an integration available?
no

Is this device already integrated in other Smart Home systems?
not applicable

Is this device already integrated in homebridge? Might the ham adapter in combination with the homebridge plugin be sufficient?
not applicable

Additional context
Some adapters states contain json content. In order to be able to work with the content of the json, the data needs to be parsed in JS or any other kind of script. For beginners this is not very handy and also for more advanced users it is a little bit annoying writing scripts for each state or adapter in order to access the data which is need.

A few examples of how this adapter works:

Tasmota Sensor Values
The reason why smart plugs with power metering are used is often times to react to certain states of said power metering. Tasmota provides all sensor information in a single state tele.SENSOR.
image

iCal Events
iCal only provides boolean states for events. If the pattern matches the event it will set events.0.now.<Eventname> = true. However, there is no further information for this event other than in the data.table state. The table state holds all events and needs to be parsed to extract more information. Using jsonExpand this information can be split into separate states for each event.
image

Now with the individual states triggers can be implemented more efficiently and also custom settings can be made for each state.

I have already implemented this via Typescript but am planning to release a adapter which will add a custom setting for each state which allows you to expand this state into either

  • the same adapter instance and adding a postfix such as SENSORx which indicates this state has been expanded from state SENSOR
  • 0_userdata
@TA2k
Copy link
Collaborator

TA2k commented Dec 21, 2023

I already implemented a package to parse json objects into ioBroker states maybe this can help here.
https://github.com/TA2k/json2iob

@AlexanderSchulz-Siemens
Copy link
Author

It looks like exactly what I want so why was it not listed in the adapters section? I searched for json and found nothing.

image

@AlexanderSchulz-Siemens
Copy link
Author

@TA2k Lets collaborate and I implement your library into an adapter?

@mcm1957
Copy link
Collaborator

mcm1957 commented Dec 21, 2023

json2iob is no adapter but a callable npm pacakge o be used by js code

I would suggest you open a issue at the adapter where you are missing expanded infomation. Expanding json data without knowlegde about the contents is not desired, as setting meaningful units and roles would not be possible.

json states can be used by scripts without any problems. And - as far as I know - json data can be used by some widgets within visualisation too.

@AlexanderSchulz-Siemens
Copy link
Author

@mcm1957 it looks like json2iob detect roles and such, thats not the issue. Maybe it doesn't need be that sophisticated every time. Maybe a plain state with appropriate type is enough for most cases. At least on my side.
I already checked the ical repository, there are multiple issues asking for having individual states for each event. My tasmota topics for example are directly in the mqtt instance, no separate adapter in this case.
I think there are plenty usecases where an expanded state with basic type (string, number, boolean, ...) is enough to make further automations much easier. Most users don't want to fiddle with scripts that much and would appreciate a simple solution. You can easily set roles and such afterwards manually if you really need it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants