Crewski / njsPC-HA

Home Assistant integration for nodejs-PoolController
28 stars 6 forks source link

Pump details not available in Home Assistant #9

Closed burninmoney closed 1 year ago

burninmoney commented 1 year ago

Only one entity is created "switch.pool" with name "Pool". I do not see any details on the pump and RPMs. I want to be able to make automated decisions based on pool RPM. I am using a virtual controller on a Raspberry Pi for the pump. Not connected to an IntelliCenter Pool Controller. My /state/all details are included below as needed.

Note I am running https://github.com/tagyoureit/nodejs-poolController version 6.1.0, which is significantly behind the current version 7.6.1. I am migrating from ST to HA.

If there are small tweaks I can make to ensure 6.1.0 integrates with HA, let me know and I can just make them in my local copy of njsPC-HA.

Thanks for putting this custom integration together.

{"time":"2021-02-04T05:04:00.205+0000","valve":0,"delay":{},"batteryVoltage":0,"status":{"val":1,"name":"ready","desc":"Ready","percent":100},"mode":{"val":0,"name":"auto","desc":"Auto"},"appVersion":"6.1.0","appVersionState":{"installed":"6.1.0","status":{"val":0,"name":"current","desc":"On current version"},"nextCheckTime":"2021-02-06T05:03:39.298+0000","githubRelease":"6.1.0","equipmentType":"appVersion"},"clockMode":{"val":12,"name":"12 Hour"},"clockSource":{"val":3,"name":"server","desc":"Server"},"sunrise":"","sunset":"","temps":{"units":{"val":0,"name":"F","desc":"Fahrenheit"},"bodies":[{"id":1,"heatMode":{"val":0},"name":"Pool","circuit":6,"heatStatus":{"val":0,"name":"off","desc":"Off"},"isOn":true}],"equipmentType":"temps"},"equipment":{"model":"Virtual Controller","maxBodies":1,"equipmentType":"equipment","softwareVersion":"","bootLoaderVersion":""},"pumps":[{"id":1,"type":{"val":128,"name":"vs","desc":"Intelliflo VS","maxPrimingTime":6,"minSpeed":450,"maxSpeed":3450,"speedStepSize":10,"maxCircuits":8,"hasAddress":true},"status":{"name":"off","desc":"Off","val":0},"targetSpeed":2450,"virtualControllerStatus":{"val":1,"name":"running","desc":"Running"},"command":10,"mode":9,"driveState":1,"watts":825,"rpm":2450,"flow":0,"ppc":44,"name":"Intelliflo VS","time":1235,"equipmentType":"pump","minSpeed":450,"maxSpeed":3450,"speedStepSize":10,"circuits":[{"id":1,"circuit":{"id":6,"name":"Pool","type":{"val":6,"name":"generic","desc":"Generic"},"isOn":true,"equipmentType":"circuit"},"units":{"val":0,"name":"rpm","desc":"RPM"},"speed":2450},{"id":2,"circuit":{"equipmentType":"circuit","id":0,"name":"Not Used","speed":0},"units":{"val":0,"name":"rpm","desc":"RPM"}},{"id":3,"circuit":{"equipmentType":"circuit","id":0,"name":"Not Used","speed":0},"units":{"val":0,"name":"rpm","desc":"RPM"}},{"id":4,"circuit":{"equipmentType":"circuit","id":0,"name":"Not Used","speed":0},"units":{"val":0,"name":"rpm","desc":"RPM"}},{"id":5,"circuit":{"equipmentType":"circuit","id":0,"name":"Not Used","speed":0},"units":{"val":0,"name":"rpm","desc":"RPM"}},{"id":6,"circuit":{"equipmentType":"circuit","id":0,"name":"Not Used","speed":0},"units":{"val":0,"name":"rpm","desc":"RPM"}},{"id":7,"circuit":{"equipmentType":"circuit","id":0,"name":"Not Used","speed":0},"units":{"val":0,"name":"rpm","desc":"RPM"}},{"id":8,"circuit":{"equipmentType":"circuit","id":0,"name":"Not Used","speed":0},"units":{"val":0,"name":"rpm","desc":"RPM"}}]},{"id":2,"type":{"val":0,"name":"none","desc":"No pump","maxCircuits":0,"hasAddress":false,"hasBody":false},"virtualControllerStatus":{"val":1,"name":"running","desc":"Running"},"targetSpeed":0,"equipmentType":"pump","circuits":[{"id":1,"circuit":{"equipmentType":"circuit","id":0,"name":"Not Used","speed":0},"units":{"val":0,"name":"rpm","desc":"RPM"}},{"id":2,"circuit":{"equipmentType":"circuit","id":0,"name":"Not Used","speed":0},"units":{"val":0,"name":"rpm","desc":"RPM"}},{"id":3,"circuit":{"equipmentType":"circuit","id":0,"name":"Not Used","speed":0},"units":{"val":0,"name":"rpm","desc":"RPM"}},{"id":4,"circuit":{"equipmentType":"circuit","id":0,"name":"Not Used","speed":0},"units":{"val":0,"name":"rpm","desc":"RPM"}},{"id":5,"circuit":{"equipmentType":"circuit","id":0,"name":"Not Used","speed":0},"units":{"val":0,"name":"rpm","desc":"RPM"}},{"id":6,"circuit":{"equipmentType":"circuit","id":0,"name":"Not Used","speed":0},"units":{"val":0,"name":"rpm","desc":"RPM"}},{"id":7,"circuit":{"equipmentType":"circuit","id":0,"name":"Not Used","speed":0},"units":{"val":0,"name":"rpm","desc":"RPM"}},{"id":8,"circuit":{"equipmentType":"circuit","id":0,"name":"Not Used","speed":0},"units":{"val":0,"name":"rpm","desc":"RPM"}}]}],"valves":[],"heaters":[],"chlorinators":[{"id":1,"currentOutput":0,"virtualControllerStatus":{"val":0,"name":"stopped","desc":"Stopped"},"equipmentType":"chlorinator"}],"circuits":[{"id":6,"name":"Pool","type":{"val":6,"name":"generic","desc":"Generic"},"isOn":true,"equipmentType":"circuit"}],"features":[],"circuitGroups":[],"lightGroups":[],"virtualCircuits":[],"covers":[],"schedules":[],"chemControllers":[]}

Crewski commented 1 year ago

Do you see any errors in Home Assistant logs when its trying to setup the sensors? I don't know how v6.1.0 operates, but the JSON you posted looks the same as the current version so I would guess things are relatively the same.

burninmoney commented 1 year ago

If these logs do not help, I can dig for some more.

Logger: homeassistant.components.number Source: custom_components/njspc_ha/number.py:22 Integration: Number (documentation, issues) First occurred: 3:57:16 PM (1 occurrences) Last logged: 3:57:16 PM

Error while setting up njspc_ha platform for number Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/njspc_ha/number.py", line 22, in async_setup_entry if chlorinator["body"]["val"] == 0 or chlorinator["body"]["val"] == 32: KeyError: 'body'

Logger: homeassistant.components.sensor Source: custom_components/njspc_ha/sensor.py:533 Integration: Sensor (documentation, issues) First occurred: 3:57:16 PM (1 occurrences) Last logged: 3:57:16 PM

Error while setting up njspc_ha platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 281, in _async_setup_platform await asyncio.shield(task) File "/config/custom_components/njspc_ha/sensor.py", line 55, in async_setup_entry new_devices.append(StatusSensor(coordinator, pump, EVENT_PUMP)) File "/config/custom_components/njspc_ha/sensor.py", line 533, in init self._value = self._equipment[STATUS][DESC] KeyError: 'status'

Crewski commented 1 year ago

I just pushed an update to the development branch to hopefully fix those errors. Test it out and see what you get. Let me know how it goes.

burninmoney commented 1 year ago

Sweet. Tested. Looks like it's working! switch.pool shows on (and RPMs, and Watts are showing now). sensor.intelliflo_vs_status shows "off" but I am 99% certain this is a known bug in 6.1.0. I'm happy! Thanks!

image

image

image

burninmoney commented 1 year ago

Found another issue. Toggling the Pool object on/off doesn't work. It does capture state - if turned on through other means, but I can't use the switch object. Here is the error:

This error originated from a custom integration.

Logger: homeassistant Source: custom_components/njspc_ha/sensor.py:325 Integration: njsPC-HA (documentation, issues) First occurred: December 28, 2022 at 9:32:09 PM (11 occurrences) Last logged: 1:37:55 AM

Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/local/lib/python3.10/site-packages/socketio/asyncio_client.py", line 465, in _handle_eio_message await self._handle_event(pkt.namespace, pkt.id, pkt.data) File "/usr/local/lib/python3.10/site-packages/socketio/asyncio_client.py", line 335, in _handle_event r = await self._trigger_event(data[0], namespace, data[1:]) File "/usr/local/lib/python3.10/site-packages/socketio/asyncio_client.py", line 391, in _trigger_event ret = await self.handlers[namespace][event](args) File "/config/custom_components/njspc_ha/init.py", line 112, in handle_pump self.async_set_updated_data(data) File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 346, in async_set_updated_data self.async_update_listeners() File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 121, in async_update_listeners update_callback() File "/config/custom_components/njspc_ha/sensor.py", line 279, in _handle_coordinator_update self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 545, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 586, in _async_write_ha_state attr.update(self.extra_state_attributes or {}) File "/config/custom_components/njspc_ha/sensor.py", line 325, in extra_state_attributes "min_flow": self._pump["minFlow"], KeyError: 'minFlow'

Crewski commented 1 year ago

In dashpanel, you should be able to open the developer tools on your browser and see the api calls its making. When you toggle the pool, there should be an entry in the console that looks like below. Can you let me know what yours look like?
image

The error listed in you logs looks like it has to do with the pump flow sensor (specifically adding attributes for min and max flow), that shouldn't be related to you not being able to turn the pool on/off. Should be an easy fix but lets focus on being able to correctly toggle the pool real quick.

burninmoney commented 1 year ago

Thanks. Turns out I had an issue with the pool controller app. Fixed it. However, another issue I’ve noticed is there isn’t a regular refresh of watts and rpm. I know the watts vary even just slightly, and watts reported don’t match poolController-webClient.

I also have noticed when the pool entity goes unavailable, and connectivity/app API restored, it doesn’t refresh to available until I restart the integration. Thoughts?

Crewski commented 1 year ago

Admittedly I don't know anything about the 6.1 version of njsPC (I started when it was already at 7.7), so I'm just guessing at things. The initial population of entities and values are from a GET request. After that, this integration uses socketio to get updates from njsPC, it sounds like that isn't happening. So maybe 6.1 didn't use socketio since that was before dashPanel? Another possibility is that the socketio is locked into localhost only and you need to change your config.json somehow? This is from the njsPC readme: This app has the default to only listen to clients from localhost (127.0.0.1). If you need to have clients connect from other machines you will need to change the [ip](https://github.com/tagyoureit/nodejs-poolController#module_nodejs-poolController--config.json) in config.json.

burninmoney commented 1 year ago

Thanks @Crewski for all the quick help. Seeing as though we did get 6.1 working on initial set up, but regular data updates were failing, I drew the line in the sand and just decided to upgrade the controller to 7.7. Everything working perfectly now with your integration. Thank you for the time you put into this thread and the entire integration.