itchannel / apex-ha

Local Neptune Apex HA Integration (Aquarium Controller)
GNU General Public License v3.0
22 stars 3 forks source link

IOTA pump is not exposed #13

Open brettonw opened 2 years ago

brettonw commented 2 years ago

HA no longer has an IOTA integration, so I hoped my Sicce pump would be exposed through the Apex. It shows up in the rest interface, but I imagine that will require some custom coding to control it.

itchannel commented 2 years ago

Could you please provide a copy Of your status.json from your controller so I can see the information required for adding it.

brettonw commented 2 years ago

status.json.txt

Not strict JSON, but should do. It is a control value as well.

itchannel commented 2 years ago

Thanks for the output I can see your Sicce pump in the outputs. What exactly can you control on it from HA.

status: [
                "TBL",
                "75",
                "OK",
                ""
            ] 

I'd need to work out what TBL and the "75" value are. I'm guessing "75" is the pump intensity.

brettonw commented 2 years ago

I think TBL is the schedule indicator. I’ll see what else I can set, but 75 is the pump setting (75%).

On Aug 24, 2022, at 7:03 PM, itchannel @.***> wrote:

 Thanks for the output I can see your Sicce pump in the outputs. What exactly can you control on it from HA.

          "TBL",
          "75",
          "OK",
          ""
      ]```

I'd need to work out what TBL and the "75" value are. I'm guessing "75" is the pump intensity. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

brettonw commented 2 years ago

I changed it to not use the wizard, just a "Set 75". The status changed too (I also changed the pump name).

{ status: [ "AON", "75", "OK", "" ], intensity: 75, name: "Sicce_Return", gid: "", type: "iotaPump|Sicce|Syncra", ID: 19, did: "3_1" }

itchannel commented 2 years ago

Thanks. Out of interest how did iOTA represent this entity in HA. I'm thinking a sensor showing intensity (Service to change intensity) and a switch with current mode. Other alternative is to use a fan sensor to represent the pump (if doable)

brettonw commented 2 years ago

I never got IOTA to work. HA removed the "official" integration and I haven't found another. I was really hoping for it to be exposed here. ;) I think it can be exposed exactly like a variable. How are you reverse engineering the REST interface? There must be a way to send the actual program numbers to the interface.

itchannel commented 2 years ago

I'm not even bothering with a proxy just using network tools in the browser as it's a simple json rest API. I'm going to guess that adding the ability to set variables is as simple as sending the same json as toggling outputs but adding in the percentage variable. If that is the case then it's fairly easy to add.

If you have 5mins could you use dev tools/network in your browser and send me the output of the post request that is sent to the controller when you change the intensity of your pump.

brettonw commented 2 years ago

Request URL: http://apex.local/rest/config/oconf/3_1 Request Method: PUT

Payload: { "name": "Sicce_Return", "icon": "Up/Down Arrows", "ctype": "Advanced", "log": false, "inuse": true, "type": "iotaPump|Sicce|Syncra", "did": "3_1", "gid": "", "gtype": "0", "ID": "19", "prog": "Set 75\n", "extra": { "temperature": true, "gph": { "min": 0, "max": 0 }, "modes": [ { "id": 0, "name": "Constant" }, { "id": 1, "name": "Lagoonal ripple" }, { "id": 2, "name": "Sharp break" }, { "id": 3, "name": "Reef crest" }, { "id": 4, "name": "Slow current" }, { "id": 5, "name": "Fast current" } ] } }

Response: {"name":"Sicce_Return","icon":"Up/Down Arrows","ctype":"Advanced","log":false,"inuse":true,"type":"iotaPump|Sicce|Syncra","did":"3_1","gid":"","gtype":"0","ID":"19","prog":"Set 75\n","extra":{"temperature":true,"gph":{"min":0,"max":0},"modes":[{"id":0,"name":"Constant"},{"id":1,"name":"Lagoonal ripple"},{"id":2,"name":"Sharp break"},{"id":3,"name":"Reef crest"},{"id":4,"name":"Slow current"},{"id":5,"name":"Fast current"}]},"errorCode":0,"errorMessage":""}

brettonw commented 2 years ago

The "extra" part doesn't seem to actually be applicable to the settings unless you are trying to send a schedule. The screen in apex fusion is like this:

Screen Shot 2022-08-24 at 11 01 17 PM
brettonw commented 2 years ago

but switching back to advanced mode, just like a variable:

Screen Shot 2022-08-24 at 11 03 11 PM
brettonw commented 2 years ago

Confirmed I can turn the switch on an off like an outlet. Next is testing whether the set variable service works on it too. Can you expose the sicce pump as a sensor variable the same way any other variable is? I know I can access the intensity attribute, but I'm wondering about whether it should be exposed as an input_number.

brettonw commented 2 years ago

Using the developer tools, I tried to call set variable on the pump and it does not work ("unknown error" is reported). The log contains:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 646, in handle_execute_script await script_obj.async_run(msg.get("variables"), context=context) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1513, in async_run await asyncio.shield(run.async_run()) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 405, in async_run await self._async_step(log_exceptions=False) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 449, in _async_step self._handle_exception( File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 472, in _handle_exception raise exception File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 447, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 680, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/config/custom_components/apex/init.py", line 74, in async_set_variable_service await hass.async_add_executor_job(set_variable, hass, service_call, coordinator) File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/apex/init.py", line 99, in set_variable did = service.data.get("did").strip() AttributeError: 'int' object has no attribute 'strip'

Would you like me to enable logging and try again?

This is important because I don't run the pump at 100% (on/off). I run it at 50%-75%.

brettonw commented 2 years ago

The problem seems to be that the did for this object is "3_1", which is getting converted to an integer somewhere in the read from the setup. Adding quotes around it in the call solved that.

brettonw commented 2 years ago

The only problem now is that the IOTA pump is not included in the sensors list (excluded by line 22 of sensor.py?). Since I am controlling the pump via an input_number, it's not really material, but it would be nice to be able to verify that the pump is actually set to the value I requested.

itchannel commented 2 years ago

Using the developer tools, I tried to call set variable on the pump and it does not work ("unknown error" is reported). The log contains:

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 646, in handle_execute_script await script_obj.async_run(msg.get("variables"), context=context) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1513, in async_run await asyncio.shield(run.async_run()) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 405, in async_run await self._async_step(log_exceptions=False) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 449, in _async_step self._handle_exception( File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 472, in _handle_exception raise exception File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 447, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 680, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/config/custom_components/apex/init.py", line 74, in async_set_variable_service await hass.async_add_executor_job(set_variable, hass, service_call, coordinator) File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, self.kwargs) File "/config/custom_components/apex/init**.py", line 99, in set_variable did = service.data.get("did").strip() AttributeError: 'int' object has no attribute 'strip'

Would you like me to enable logging and try again?

This is important because I don't run the pump at 100% (on/off). I run it at 50%-75%.

Interesting little bug, looks like HA auto converts inputs to integers and strings depending on whats input. I'll just cast the input always to a string and that should fix that use case and avoid the quotes

itchannel commented 2 years ago

The only problem now is that the IOTA pump is not included in the sensors list (excluded by line 22 of sensor.py?). Since I am controlling the pump via an input_number, it's not really material, but it would be nice to be able to verify that the pump is actually set to the value I requested.

I can add it back as a sensor if it would be of use. Also as mentioned I am looking at putting pumps as a proper sensor type like a fan 👍

brettonw commented 2 years ago

As a test I changed line 22, and I have the sensor value showing up now, so it really is that simple. I'm debating whether to try to set my input number if it changes, but I'm worried about some sort of backlash effect. I'll try it.