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

Capture only the last value #32

Open
snagytx opened this issue Nov 3, 2021 · 2 comments
Open

Capture only the last value #32

snagytx opened this issue Nov 3, 2021 · 2 comments

Comments

@snagytx
Copy link

snagytx commented Nov 3, 2021

Hello,

Not sure if this is an enhancement request or the functionality is there but I didn't see it.

I'm looking to track the dosing volume - it doesn't seem that we can get dosing time.

Making some changes I was able to get PHVOL & PHMOD from intellichem to be sent by intellicenter.

The issue is that PHVOL is always starting at 0 them increasing every second until the dosing ends. So that means that the sensor would be set to multiple times - in a dosing. We can't really apply any formulas on this in HomeAssistant to get the "Today's usage" or "This Week's usage" or so on.

For example we would get, the values are just for exemplification: 0, 1, 3, 4, 6, 0, 2, 3, 4, 5, 0, 1, 2 - we would need to set the PHVOL sensor to 6, 5, 2 - because we dosed 3 time .

What I noticed is that PHMOD is set to ON most of the time, once the dosing starts it's set to OFF, then once the dosing ends it's set to ON again.

We would need to build a logic to retail the last PHVOL we received before PHMOD is switched from OFF to ON, and ignore all the other PHVOL.

If you have any recommendations on how to implement it, let me know.

A snippet of how the messages are sent:

2021-11-03 14:58:45 DEBUG (MainThread) [custom_components.intellicenter.pyintellicenter.protocol] PROTOCOL: received from transport: {"command":"NotifyList","messageID":"260a287b-7436-4392-8ce8-d48bb9fe67f9","objectList":[{"objnam":"CHM01","params":{"PHMOD":"ON"}}]}
2021-11-03 14:58:46 DEBUG (MainThread) [custom_components.intellicenter.pyintellicenter.protocol] PROTOCOL: received from transport: {"command":"NotifyList","messageID":"d8e55187-6a86-4f7b-945c-2315bfdee935","objectList":[{"objnam":"CHM01","params":{"PHVOL":"1024"}}]}
2021-11-03 14:58:46 DEBUG (MainThread) [custom_components.intellicenter.pyintellicenter.protocol] PROTOCOL: received from transport: {"command":"NotifyList","messageID":"d5bb6a77-b8b3-44e1-bd42-85da2df8133a","objectList":[{"objnam":"CHM01","params":{"PHMOD":"OFF"}}]}
2021-11-03 14:58:47 DEBUG (MainThread) [custom_components.intellicenter.pyintellicenter.protocol] PROTOCOL: received from transport: {"command":"NotifyList","messageID":"0fa3af59-2945-43bc-8038-f40a5fe72453","objectList":[{"objnam":"CHM01","params":{"PHVOL":"1536"}}]}
2021-11-03 14:58:48 DEBUG (MainThread) [custom_components.intellicenter.pyintellicenter.protocol] PROTOCOL: received from transport: {"command":"NotifyList","messageID":"cd219d42-0418-4fac-874a-684ca2528511","objectList":[{"objnam":"CHM01","params":{"PHVOL":"2048"}}]}
2021-11-03 14:58:50 DEBUG (MainThread) [custom_components.intellicenter.pyintellicenter.protocol] PROTOCOL: received from transport: {"command":"NotifyList","messageID":"006dee11-0c06-43a5-a1e8-fd207460a39a","objectList":[{"objnam":"CHM01","params":{"PHVOL":"3328"}}]}
2021-11-03 14:58:51 DEBUG (MainThread) [custom_components.intellicenter.pyintellicenter.protocol] PROTOCOL: received from transport: {"command":"NotifyList","messageID":"018fbe28-2841-4c81-af3f-202993f2fe55","objectList":[{"objnam":"CHM01","params":{"PHVOL":"3840"}}]}
2021-11-03 14:58:52 DEBUG (MainThread) [custom_components.intellicenter.pyintellicenter.protocol] PROTOCOL: received from transport: {"command":"NotifyList","messageID":"9f4c1f1b-4f31-44af-811a-424d02857c37","objectList":[{"objnam":"CHM01","params":{"PHVOL":"4352"}}]}
2021-11-03 14:58:54 DEBUG (MainThread) [custom_components.intellicenter.pyintellicenter.protocol] PROTOCOL: received from transport: {"command":"NotifyList","messageID":"1b2b935b-6330-467e-a981-275884dee5d0","objectList":[{"objnam":"CHM01","params":{"PHVOL":"5376"}}]}
2021-11-03 14:58:55 DEBUG (MainThread) [custom_components.intellicenter.pyintellicenter.protocol] PROTOCOL: received from transport: {"command":"NotifyList","messageID":"7211e239-5a55-491b-9981-33f6448037fb","objectList":[{"objnam":"CHM01","params":{"PHVOL":"6144"}}]}
2021-11-03 14:58:56 DEBUG (MainThread) [custom_components.intellicenter.pyintellicenter.protocol] PROTOCOL: received from transport: {"command":"NotifyList","messageID":"785f8b6c-227e-4ae2-a305-268f24c19acf","objectList":[{"objnam":"CHM01","params":{"PHVOL":"6656"}}]}
2021-11-03 14:58:57 DEBUG (MainThread) [custom_components.intellicenter.pyintellicenter.protocol] PROTOCOL: received from transport: {"command":"NotifyList","messageID":"d2e5040f-7328-4100-8d51-ad8a35d9200d","objectList":[{"objnam":"CHM01","params":{"PHVOL":"7168"}}]}
2021-11-03 14:58:59 DEBUG (MainThread) [custom_components.intellicenter.pyintellicenter.protocol] PROTOCOL: received from transport: {"command":"NotifyList","messageID":"1a883c89-8c09-4bc1-a688-7f197cd208dd","objectList":[{"objnam":"CHM01","params":{"PHVOL":"7680"}}]}
2021-11-03 14:58:59 DEBUG (MainThread) [custom_components.intellicenter.pyintellicenter.protocol] PROTOCOL: received from transport: {"command":"NotifyList","messageID":"1a3da47e-4c7f-4bcd-86c1-779d1bc3e50a","objectList":[{"objnam":"CHM01","params":{"PHMOD":"ON"}}]}

I don't know why but the reported PHVOL is 256*X, where X is the milliliters that were dosed.

@jlvaillant
Copy link
Owner

I don't have (yet) a IntelliChem unit so I am completely unable to test or debug that part of the code that was contributed.
Do you think you could do the logic you are describing in a python script triggered by the status change of PHMOD? or use a template to get the MAX of the PHVOL value per day?

@snagytx
Copy link
Author

snagytx commented Dec 7, 2021

I tried to do that in HA, but for me it's very important to get discrete/final numbers and no duplicates, since I wanted to be able to sum the values to calculate the daily/weekly/monthly dosages.

What I did was to write an automation to monitor for PHMOD and when it turns from OFF to ON then publish to an MQTT topic with the value of PHVOL divided by 256. Then have another sensor subscribe to that topic. But I hit another issue - if the dosing was more than 256ml, the PHVOL would reset to 1 without PHMOD changing from OFF to ON. So it would be something like:

PHMOD->OFF
PHVOL->0
.....
PHVOL->65536 == 256*256
PHVOL->1
...
PHVOL->2560 == 256*10
PHMOD->ON

This is not something possible with an automation since it would need to do some math 256+10=>266 ml .

I did not look into scripts. I only tried to update this integration but I didn't find a way to same the PHVOL in a temporary variable that could be later retrieved and used, but I'm not very familiar with multithreaded python to really feel conformable to take this task up.

In the end I ended up installing nodejs-poolController and configured it to publish to MQTT and then extract the data from there in seconds then do the math for ml. Even njsPC didn't work initially too good - it was "blind coded" for IntelliChem but was able to adjust it and fix the issue. Now it's working flawless.

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

No branches or pull requests

2 participants