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

Option/Ability to ignore missing values in JSON #129

Open
sillyfrog opened this issue Aug 28, 2018 · 2 comments
Open

Option/Ability to ignore missing values in JSON #129

sillyfrog opened this issue Aug 28, 2018 · 2 comments

Comments

@sillyfrog
Copy link
Contributor

Thanks for #67 - just started using it now! :)

Much like the original posts on #67, I'm using Tasmota. I have a dimmable light, but unfortunately Tasmota will often output the following:

stat/light/RESULT {"POWER":"ON","Dimmer":54,"Color":"00000089","HSBColor":"0,0,0","Channel":[0,0,0,54]}
stat/light/RESULT {"POWER":"ON"}

It will also output just the second line if only the power was switched (and the Dimmer was not changed).

Would it be possible to have an option to ignore updates if the value is not present in the JSON. For example, I'm currently matching on just Dimmer - but if there was some sort of alternate syntax supported (just an idea), say ..Dimmer - if the value was not in the JSON, rather than treating it as 0 or false it would just ignore it, and treat it as if it was not sent.

Thanks again!

@hobbyquaker
Copy link
Owner

hobbyquaker commented Aug 28, 2018

Hmm, that's not so easy to accomplish, I'm caching the payload of all incoming topics, so if an iOS device issues a HAP Get I'm reading the value from that cache. But when a payload with a missing property overwrites the previous entry in the cache I have no possibility to answer on a Get request for the then missing property - because homekit2mqtt has no knowledge of the previous payload(s) - in your example I can't give an answer to a Get on the dimmer value after {"POWER":"ON"} overwrote the cache.
It's not impossible - but it's huge effort (first idea: keeping a distinct cache for all characteristics). Will think about it, maybe I come up with a easier solution, give me some time.

@sillyfrog
Copy link
Contributor Author

Another thought on this, what if it merged any incoming JSON data with existing data? I'm extremely naive when in comes to node, so may not work. I'm thinking something such as this: https://stackoverflow.com/questions/14974864/combine-or-merge-json-on-node-js-without-jquery

I've tried to figure it out in the code quickly, but not getting too far, if you have some quick pointers where the incoming messages are saved, I can try and see if I can come up with a patch that'll work.

Thanks again!

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

2 participants