MikeJMcGuire / hass-actronque

Actron Que/Neo Air Conditioner Add-On for Home Assistant
GNU General Public License v3.0
13 stars 5 forks source link

Feature request - Sensor for HTTP response status codes when sending API requests #15

Closed dragonspy00 closed 9 months ago

dragonspy00 commented 9 months ago

Hi Mike,

Just wanted to submit a feature request of maybe adding a sensor that can display the HTTP status codes of past commands?

Because the Actron Que servers/API are complete crud, most requests like setting temperature or turning the AC on/off end with 503 or 504 errors like below:

13-12-2023 13:23:37.43 Que.ProcessQueue() Attempting Command: 0x000036AA
13-12-2023 13:23:37.43 Que.SendCommand() [0x000036AA] Base: https://que.actronair.com.au/api/v0/client/ac-systems/cmds/send?serial=######
13-12-2023 13:23:37.43 Que.SendCommand() [0x000036AA] Content: {"command":{"type":"set-settings","UserAirconSettings.EnabledZones[2]":true}}
13-12-2023 13:23:41.98 Que.SendCommand() [0x000036AA] Error: Unable to process API response: GatewayTimeout/Gateway Timeout

It'll be helpful if there was a sensor that captures the HTTP response status codes so we can use an automation in HASS to retry the command until it's successful.

MikeJMcGuire commented 9 months ago

Howdy, yep, I can do that. I can probably have it retry once or twice first though too.

MikeJMcGuire commented 9 months ago

I've reduced the queue retry timer significantly, and increased the command expiry, so it should now retry automatically 1 - 2 times.

MikeJMcGuire commented 9 months ago

See how it goes like this, if its still having an issue with 2-3 consecutive retries, then I'll put something in to signal that it failed.

MikeJMcGuire commented 9 months ago

Updated in v2023.12.0. Let me know how you go.

dragonspy00 commented 9 months ago

See how it goes like this, if its still having an issue with 2-3 consecutive retries, then I'll put something in to signal that it failed.

Thanks heaps for the changes Mike but unfortunately, looks like it's still failing intermittently:

19-12-2023 10:59:19.61 MQTT.MessageProcessor() actronque########/zone2/mode/set
19-12-2023 10:59:19.62 Service.MQTTProcessor() [0x00000C84] actronque########/zone2/mode/set
19-12-2023 10:59:19.62 Que.ChangeZone() [0x00000C84] Unit: ########, Zone 2: On
19-12-2023 10:59:19.62 Que.AddCommandToQueue() [0x00000C84]
19-12-2023 10:59:19.62 Que.ProcessQueue()
19-12-2023 10:59:19.62 Que.ProcessQueue() Attempting Command: 0x00000C84
19-12-2023 10:59:19.62 Que.ChangeMode() [0x00000C84] Unit: ########, Mode: Fan_Only
19-12-2023 10:59:19.62 Que.AddCommandToQueue() [0x00000C84]
19-12-2023 10:59:19.62 Que.SendCommand() [0x00000C84] Base: https://que.actronair.com.au/api/v0/client/ac-systems/cmds/send?serial=########
19-12-2023 10:59:19.64 Que.SendCommand() [0x00000C84] Content: {"command":{"type":"set-settings","UserAirconSettings.EnabledZones[1]":true}}
19-12-2023 10:59:19.95 MQTT.SendMessage() hass-actronque########/status
19-12-2023 10:59:24.19 Que.SendCommand() [0x00000C84] Error: Unable to process API response: GatewayTimeout/Gateway Timeout
19-12-2023 10:59:24.19 Que.ProcessQueue() Attempting Command: 0x00000C84
19-12-2023 10:59:24.19 Que.SendCommand() [0x00000C84] Base: https://que.actronair.com.au/api/v0/client/ac-systems/cmds/send?serial=########
19-12-2023 10:59:24.19 Que.SendCommand() [0x00000C84] Content: {"command":{"type":"set-settings","UserAirconSettings.EnabledZones[1]":true}}
19-12-2023 10:59:28.74 Que.SendCommand() [0x00000C84] Error: Unable to process API response: GatewayTimeout/Gateway Timeout
19-12-2023 10:59:28.74 Que.ProcessQueue() Attempting Command: 0x00000C84
19-12-2023 10:59:28.74 Que.SendCommand() [0x00000C84] Base: https://que.actronair.com.au/api/v0/client/ac-systems/cmds/send?serial=########
19-12-2023 10:59:28.74 Que.SendCommand() [0x00000C84] Content: {"command":{"type":"set-settings","UserAirconSettings.EnabledZones[1]":true}}
19-12-2023 10:59:33.29 Que.SendCommand() [0x00000C84] Error: Unable to process API response: GatewayTimeout/Gateway Timeout
19-12-2023 10:59:33.29 Que.ProcessQueue() Attempting Command: 0x00000C84
19-12-2023 10:59:33.29 Que.ProcessQueue() Command Expired: 0x00000C84
19-12-2023 10:59:33.29 Que.ProcessQueue() Attempting Command: 0x00000C84
19-12-2023 10:59:33.29 Que.ProcessQueue() Command Expired: 0x00000C84
19-12-2023 10:59:33.29 Que.ProcessQueue() Complete

Something to signal the failure will be good because I can then add an alert telling me my efforts are futile and to get up off my bum and use the physical controller :P

MikeJMcGuire commented 9 months ago

Sigh. Well, good to see the retry logic is working well. Ok, so if it fails the retries, I'll have it do something to signal the failure. Not sure what yet. I don't really want to set an entity status, as its more of an event. Given its MQTT anyway, I'll probably just have it publish an MQTT event. Does that work?

dragonspy00 commented 9 months ago

Yep that works for me!

MikeJMcGuire commented 9 months ago

I'll have it post with the topic actronqueXXXXX/lastfailedcommand, and the payload will be the sequential id of the failed command. The XXXX is the serial number of the unit, which is the same topic format for the other messages.

MikeJMcGuire commented 9 months ago

Ok, v2023.12.1 - give that a try.

dragonspy00 commented 9 months ago

Thanks Mate!

With how poor their cloud service is, it didn't take very long to get a successful test.

If anyone stumbles across this and is interested... here's my template automation (serial blanked out):

alias: Actron command fail alert
description: ""
trigger:
  - platform: mqtt
    topic: actronque########/lastfailedcommand
action:
  - service: persistent_notification.create
    data:
      message: Actron command failed
      title: Actron
  - service: notify.mobile_app_sm_g991b
    data:
      message: Actron command failed
      data:
        ttl: 0
        priority: high
mode: single
MikeJMcGuire commented 9 months ago

Thanks, yeah its certainly interesting how frequently those responses time out.