sfeakes / AquapureD

Control SWG without control panel. (Hayward Aquarite, Jandy Aquapure, Zodiac TRi)
Other
17 stars 3 forks source link

MQTT publishing wrong topic state for SWG #5

Closed Kranzy closed 3 years ago

Kranzy commented 4 years ago

Hi @sfeakes,

I have just updated to the latest release and noticed my switch in home assistant won't show off status. Always returns to on once switched. The actual pump turns on and off as expected.

Looking at the logs below, even when it receives SWG/set/0 it publishes /SWG 2 causing the switch state to not be accurate.

Debug:  MQTT: topic aquapure/SWG/set 0
Info:   Setting SWG percent to 0
Debug:  Serial read 11 bytes
Debug:  Jandy   Received AR PPM    | HEX: 0x10|0x02|0x00|0x16|0x1d|0x00|0x00|0x00|0x45|0x10|0x03|
Debug:  Received PPM 2900
Debug:  build_device_JSON 589 of 1024
Debug:  MQTT: Published id=41: aquapure/SWG/Percent 0
Debug:  MQTT: Published id=42: aquapure/SWG/Percent_f -17.78
Debug:  MQTT: Published id=43: aquapure/SWG/PPM 2900
Debug:  MQTT: Published id=44: aquapure/SWG/PPM_f 1593.33
Debug:  MQTT: Published id=45: aquapure/SWG/enabled 2
Debug:  MQTT: Published id=46: aquapure/SWG/fullstatus 0
Debug:  MQTT: Published id=47: aquapure/SWG/Boost 0
Debug:  MQTT: Published id=48: aquapure/SWG 2
Debug:  MQTT: Message publishing acknowledged (msg_id: 41)
Debug:  MQTT: topic aquapure/SWG/Percent 0
Debug:  MQTT: Didn't understand topic aquapure/SWG/Percent 0
Debug:  MQTT: Message publishing acknowledged (msg_id: 42)
Debug:  MQTT: received (msg_id: 42), looks like my own message, ignoring
Debug:  MQTT: Message publishing acknowledged (msg_id: 43)
Debug:  MQTT: received (msg_id: 43), looks like my own message, ignoring
Debug:  MQTT: Message publishing acknowledged (msg_id: 44)
Debug:  MQTT: received (msg_id: 44), looks like my own message, ignoring
Debug:  MQTT: Message publishing acknowledged (msg_id: 45)
Debug:  MQTT: received (msg_id: 45), looks like my own message, ignoring
Debug:  MQTT: Message publishing acknowledged (msg_id: 46)
Debug:  MQTT: received (msg_id: 46), looks like my own message, ignoring
Debug:  MQTT: Message publishing acknowledged (msg_id: 47)
Debug:  MQTT: received (msg_id: 47), looks like my own message, ignoring
Debug:  MQTT: Message publishing acknowledged (msg_id: 48)
Debug:  MQTT: received (msg_id: 48), looks like my own message, ignoring
Debug:  MQTT: topic aquapure/SWG/Percent/set 0.0
Info:   Setting SWG percent to 0
Debug:  build_device_JSON 589 of 1024
Debug:  MQTT: Published id=49: aquapure/SWG/Percent 0
Debug:  MQTT: Published id=50: aquapure/SWG/Percent_f -17.78
Debug:  MQTT: Published id=51: aquapure/SWG/PPM 2900
Debug:  MQTT: Published id=52: aquapure/SWG/PPM_f 1593.33
Debug:  MQTT: Published id=53: aquapure/SWG/enabled 2
Debug:  MQTT: Published id=54: aquapure/SWG/fullstatus 0
Debug:  MQTT: Published id=55: aquapure/SWG/Boost 0
Debug:  MQTT: Published id=56: aquapure/SWG 2
Debug:  MQTT: Message publishing acknowledged (msg_id: 49)
Debug:  MQTT: topic aquapure/SWG/Percent 0
Debug:  MQTT: Didn't understand topic aquapure/SWG/Percent 0
Debug:  MQTT: Message publishing acknowledged (msg_id: 50)
Debug:  MQTT: received (msg_id: 50), looks like my own message, ignoring
Debug:  MQTT: Message publishing acknowledged (msg_id: 51)
Debug:  MQTT: received (msg_id: 51), looks like my own message, ignoring
Debug:  MQTT: Message publishing acknowledged (msg_id: 52)
Debug:  MQTT: received (msg_id: 52), looks like my own message, ignoring
Debug:  MQTT: Message publishing acknowledged (msg_id: 53)
Debug:  MQTT: received (msg_id: 53), looks like my own message, ignoring
Debug:  MQTT: Message publishing acknowledged (msg_id: 54)
Debug:  MQTT: received (msg_id: 54), looks like my own message, ignoring
Debug:  MQTT: Message publishing acknowledged (msg_id: 55)
Debug:  MQTT: received (msg_id: 55), looks like my own message, ignoring
Debug:  MQTT: Message publishing acknowledged (msg_id: 56)
Debug:  MQTT: received (msg_id: 56), looks like my own message, ignoring
Debug:  Jandy   Sent     AR %%     | HEX: 0x00|0x10|0x02|0x50|0x11|0x00|0x73|0x10|0x03|0x00|
Debug:  Serial read 11 bytes
Debug:  Jandy   Received AR PPM    | HEX: 0x10|0x02|0x00|0x16|0x1d|0x00|0x00|0x00|0x45|0x10|0x03|
Debug:  Received PPM 2900
Debug:  Jandy   Sent     AR %%     | HEX: 0x00|0x10|0x02|0x50|0x11|0x00|0x73|0x10|0x03|0x00|
Debug:  Serial read 11 bytes
Debug:  Jandy   Received AR PPM    | HEX: 0x10|0x02|0x00|0x16|0x1d|0x00|0x00|0x00|0x45|0x10|0x03|
Debug:  Received PPM 2900
^CNotice: Stopping!
Kranzy commented 4 years ago

Hey @sfeakes any idea when this change came in? I’m thinking of rolling my instal back to a previous version but because I skipped a few versions to the latest I’m not sure which version to roll back to?

Kranzy commented 4 years ago

Hi @sfeakes

Im having to replace the SD card in my pi this weekend.

Would love to run the latest version of the software but the wrong topic state for SWG is a breaker for me at the moment.

Are you going to continue developing this project? I understand if you're not, just want to look at my options moving forward.

sfeakes commented 4 years ago

Not sure how I missed this. I’ll take a look later in the week and fully understand what you mean. but quickly. I think you need to use both the enable and state Topics. You have several options so the SWG acts just like thermostat in automation hubs. You have (for thermostat) the following. Off (I’m not doing anything under any circumstances) Enabled (Ie I will turn on when I need to) Heating. Cooling.

Since. SWG is mimicking a thermostat in (cooling only) mode, you use both the enabled and state topics. Problem you have is SWG is never off (If it’s powered), so when you Set it to 0% generation , it should go into “enabled” state. But let me take a more detail look at this and home assistant.

Kranzy commented 4 years ago

So for me I am using the mqtt to create my own sensors/sliders etc. I am not setting it up as a climate unit so no need to adjust that side of it.

I use my own template to determine the different state based on the following

My variables based on the mqtt topics

swg_power_state_topic: aquapure/SWG
swg_power_command_topic: aquapure/SWG/set
swg_boost_state_topic: aquapure/SWG/Boost
swg_boost_command_topic: aquapure/SWG/Boost/set
swg_ppm_state_topic: aquapure/SWG/PPM
swg_full_status_state_topic: aquapure/SWG/fullstatus

Logic to show if it is off/on & status

platform: template
sensors:
  swg_status_values:
    friendly_name: "SWG Status"
    value_template: >-
      {% if is_state("sensor.swg_power_status", "0") %}
        Off
      {% elif is_state("sensor.swg_status", "0") %}
        On
      {% elif is_state("sensor.swg_status", "1") %}
        No Flow
      {% elif is_state("sensor.swg_status", "2") %}
        Low Salt
      {% elif is_state("sensor.swg_status", "4") %}
        High Salt
      {% elif is_state("sensor.swg_status", "8") %}
        Clean Cell
      {% elif is_state("sensor.swg_status", "9") %}
        Turning Off
      {% elif is_state("sensor.swg_status", "16") %}
        High Current
      {% elif is_state("sensor.swg_status", "32") %}
        Low Volts
      {% elif is_state("sensor.swg_status", "64") %}
        Low Temp
      {% elif is_state("sensor.swg_status", "128") %}
        Check PCB
      {% elif is_state("sensor.swg_status", "254") %}
        No Connection to SWG
      {% elif is_state("sensor.swg_status", "255") %}
        No Connection to SWG
      {%- endif %}

It was only when updating to the latest version that I was having issues. should my 'swg_power_state_topic' be aquapured/SWG/enabled??

I should also note that I have clean cell showing on my SWG currently but that is not being shown in aquapure, unsure if the log above is enough for you to see if it should be.

Kranzy commented 4 years ago

Hi @sfeakes did you end up getting a chance to look at this? It looks like aquapure/SWG/enabled is publishing 2 when switching the SWG on and off from the web interface. aquapure/SWG set to 0 turns it off as expected, but then publishes a 2 which tells my switch it is back on but it is still off in the webui.

Kranzy commented 3 years ago

@sfeakes are you able to confirm that the 'SWG' topic should be reporting 0 when its off, and the 'SWG/enabled' topic is when connected to the SWG.

I guess my end result is I am looking to have an on/off switch to control the SWG, which had been working great up until an update or two ago (I am not exactly sure which update changed it)

Kranzy commented 3 years ago

Ok so I ended up getting around this issue by using the state topic as aquapured/SWG/Percent and in my mqtt switch settings using a value template value_template: "{% if value == '0' %}OFF{% else %}ON{% endif %}" This now gives me the switch to turn the chlorinator on/off and have the correct switch state shown.

As most people use the climate option to set this up I am happy to close this one out now I have a solution that didnt require any code changes.