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

actuatorONOFF no longer working with Home Assistant #1105

Closed
josephperry opened this issue Nov 30, 2021 · 8 comments · Fixed by #1106
Closed

actuatorONOFF no longer working with Home Assistant #1105

josephperry opened this issue Nov 30, 2021 · 8 comments · Fixed by #1106

Comments

@josephperry
Copy link
Contributor

josephperry commented Nov 30, 2021

In Home Assistant, actuatorONOFF worked in 0.9.6 but is no longer working in the 0.9.8 development version

ZactuatorONOFF.ino contains:

#ifdef ZactuatorONOFF

#  ifdef jsonReceiving
void MQTTtoONOFF(char* topicOri, JsonObject& ONOFFdata) {
  if (cmpToMainTopic(topicOri, subjectMQTTtoONOFF)) {
    Log.trace(F("MQTTtoONOFF json data analysis" CR));
    int boolSWITCHTYPE = ONOFFdata["cmd"] | 99;
    int gpio = ONOFFdata["gpio"] | ACTUATOR_ONOFF_GPIO;
    if (boolSWITCHTYPE != 99) {
      Log.notice(F("MQTTtoONOFF boolSWITCHTYPE ok: %d" CR), boolSWITCHTYPE);
      Log.notice(F("GPIO number: %d" CR), gpio);
      pinMode(gpio, OUTPUT);
      digitalWrite(gpio, boolSWITCHTYPE);
      // we acknowledge the sending by publishing the value to an acknowledgement topic
      pub(subjectGTWONOFFtoMQTT, ONOFFdata);
    } else {
      Log.error(F("MQTTtoONOFF failed json read" CR));
    }
  }
}
#  endif

yet ZmqttDiscovery.ino contains:

#  ifdef ZactuatorONOFF
  Log.trace(F("actuatorONOFFDiscovery" CR));
  char* actuatorONOFF[8] = {"switch", "actuatorONOFF", "", "", "", "{\"cmd\":1}", "{\"cmd\":0}", ""};
  //component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement

  //trc(actuatorONOFF[1]);
  createDiscovery(actuatorONOFF[0],
                  subjectGTWONOFFtoMQTT, actuatorONOFF[1], (char*)getUniqueId(actuatorONOFF[1], actuatorONOFF[2]).c_str(),
                  will_Topic, actuatorONOFF[3], actuatorONOFF[4],
                  actuatorONOFF[5], actuatorONOFF[6], actuatorONOFF[7],
                  0, "", "", true, subjectMQTTtoONOFF,
                  "", "", "", "", false, // device name, device manufacturer, device model, device mac, retain
                  stateClassNone //State Class
  );
#  endif

Is the problem with ZmqttDiscovery.ino?

@josephperry
Copy link
Contributor Author

I should be more specific: actuatorONOFF doesn't show as a switch in Home Assistant even with this in platformio.ini

'-DZactuatorONOFF="ONOFF"'
'-DACTUATOR_ON=1'
'-DRFmqttDiscovery=true'
'-DZmqttDiscovery="HADiscovery"'
'-DjsonReceiving=true'

@1technophile
Copy link
Owner

1technophile commented Nov 30, 2021

Thanks for reporting this, could you check the message you have there with MQTT explorer:
image

@josephperry
Copy link
Contributor Author

homeassistant/binary_sensor/30AEA474AF00connectivity/config
{"stat_t":"home/OpenMQTTGateway_ESP32_CUSTOM/LWT","name":"SYS: Connectivity","uniq_id":"30AEA474AF00connectivity","dev_cla":"connectivity","pl_on":"online","pl_off":"offline","pl_avail":"online","pl_not_avail":"offline","device":{"identifiers":["30AEA474AF00"],"name":"OpenMQTTGateway_ESP32_CUSTOM","model":"[\"IR\",\"RF\",\"GPIOInput\"]"}}

homeassistant/binary_sensor/30AEA474AF00GPIOInput/config
{"stat_t":"home/OpenMQTTGateway_ESP32_CUSTOM/GPIOInputtoMQTT","name":"GPIOInput","uniq_id":"30AEA474AF00GPIOInput","val_tpl":"{{ value_json.gpio | is_defined }}","pl_on":"HIGH","pl_off":"LOW","device":{"identifiers":["30AEA474AF00"],"name":"OpenMQTTGateway_ESP32_CUSTOM","model":"[\"IR\",\"RF\",\"GPIOInput\"]","manufacturer":"OMG_community"}}

homeassistant/switch/30AEA474AF00actuatorONOFF/config
{"stat_t":"home/OpenMQTTGateway_ESP32_CUSTOM/LWT","name":"SYS: Erase credentials","uniq_id":"30AEA474AF00erase","pl_on":"{\"cmd\":\"erase\"}","pl_avail":"online","pl_not_avail":"offline","cmd_t":"home/OpenMQTTGateway_ESP32_CUSTOM/commands/MQTTtoSYS/config","device":{"identifiers":["30AEA474AF00"],"name":"OpenMQTTGateway_ESP32_CUSTOM"}}

homeassistant/switch/30AEA474AF00discovery/config
{"name":"SYS: Auto discovery","uniq_id":"30AEA474AF00discovery","retain":true,"pl_on":"{\"discovery\":true}","pl_off":"{\"discovery\":false}","pl_avail":"online","pl_not_avail":"offline","cmd_t":"home/OpenMQTTGateway_ESP32_CUSTOM/commands/MQTTtoSYS/config","device":{"identifiers":["30AEA474AF00"],"name":"OpenMQTTGateway_ESP32_CUSTOM","model":null}}

homeassistant/switch/30AEA474AF00erase/config
{"stat_t":"home/OpenMQTTGateway_ESP32_CUSTOM/LWT","name":"SYS: Erase credentials","uniq_id":"30AEA474AF00erase","pl_on":"{\"cmd\":\"erase\"}","pl_avail":"online","pl_not_avail":"offline","cmd_t":"home/OpenMQTTGateway_ESP32_CUSTOM/commands/MQTTtoSYS/config","device":{"identifiers":["30AEA474AF00"],"name":"OpenMQTTGateway_ESP32_CUSTOM"}}

homeassistant/switch/30AEA474AF00restart/config
{"stat_t":"home/OpenMQTTGateway_ESP32_CUSTOM/LWT","name":"SYS: Restart gateway","uniq_id":"30AEA474AF00restart","pl_on":"{\"cmd\":\"restart\"}","pl_avail":"online","pl_not_avail":"offline","cmd_t":"home/OpenMQTTGateway_ESP32_CUSTOM/commands/MQTTtoSYS/config","device":{"identifiers":["30AEA474AF00"],"name":"OpenMQTTGateway_ESP32_CUSTOM"}}

Auto discovery also doesn't show up as a switch in Home Assistant as it did in 0.9.6

homeassistant/sensor/30AEA474AF00gatewayRF/config
{"stat_t":"home/OpenMQTTGateway_ESP32_CUSTOM/433toMQTT","name":"gatewayRF","uniq_id":"30AEA474AF00gatewayRF","val_tpl":"{{ value_json.value | is_defined }}","device":{"identifiers":["30AEA474AF00"],"name":"OpenMQTTGateway_ESP32_CUSTOM","model":"[\"IR\",\"RF\",\"GPIOInput\"]","manufacturer":"OMG_community","sw_version":"v0.9.8+ 2021-11-30 joe"}}

@josephperry
Copy link
Contributor Author

Oops, 30AEA474AF00actuatorONOFF wasn't copied correctly;

homeassistant/switch/30AEA474AF00actuatorONOFF/config
{"stat_t":"home/OpenMQTTGateway_ESP32_CUSTOM/ONOFFtoMQTT","name":"actuatorONOFF","uniq_id":"30AEA474AF00actuatorONOFF","pl_on":"{\"cmd\":1}","pl_off":"{\"cmd\":0}","cmd_t":"home/OpenMQTTGateway_ESP32_CUSTOM/commands/MQTTtoONOFF","device":{"identifiers":["30AEA474AF00"],"name":"OpenMQTTGateway_ESP32_CUSTOM","model":null}}

BTW using Home Assistant core-2021.11.5

@1technophile
Copy link
Owner

1technophile commented Dec 8, 2021

I just tried adding this to an esp32 dev with the latest development branch

  '-DZactuatorONOFF="ONOFF"'
  '-DACTUATOR_ON=1'
  '-DACTUATOR_OFF=0'
  '-DACTUATOR_ONOFF_DEFAULT=ACTUATOR_ON'

And I got this in MQTT discovery topic:
homeassistant/switch/XXXactuatorONOFF/config

{"stat_t":"home/XXX/ONOFFtoMQTT","name":"actuatorONOFF","uniq_id":"XXXactuatorONOFF","pl_on":"{\"cmd\":1}","pl_off":"{\"cmd\":0}","cmd_t":"home/XXX/commands/MQTTtoONOFF","device":{"identifiers":["XXX"],"name":"XXX","model":"[\"BT\"]","manufacturer":"OMG_community","sw_version":"version_tag"}}

And I can see the switch in HASS core-2021.11.1 or 11.5:
image

@josephperry
Copy link
Contributor Author

Figured out what the real problem is:
when the json config response ends with "model": null it is not accepted by Home Assistant.

See my previous response for value sent for the homeassistant/switch/30AEA474AF00actuatorONOFF/config topic. It can also effect the homeassistant/switch/30AEA474AF00discovery/config and other topics which Home Assistant then ignores.

When I reduced the length of the strings in the defines for Gateway_Name, OMG_VERSION, and the number of gateways included (which results in the "model" field) the problem goes away: actuatorONOFF and other configurations then work in v0.9.8.

Can the length of the json publishing string be increased to eliminate this problem? I did not see this in v0.9.6, there was no null data. Is there some upper bound on the permissible json length?

@1technophile
Copy link
Owner

1technophile commented Dec 10, 2021

Can the length of the json publishing string be increased to eliminate this problem? I did not see this in v0.9.6, there was no null data. Is there some upper bound on the permissible json length?

Yes it can, we are going to increase it for the new version, thanks for pointing this!

@1technophile 1technophile added this to the v0.9.9 milestone Dec 10, 2021
@josephperry
Copy link
Contributor Author

Thanks!

@1technophile 1technophile linked a pull request Dec 16, 2021 that will close this issue
3 tasks
@1technophile 1technophile removed this from the v0.9.9 milestone Dec 16, 2021
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

Successfully merging a pull request may close this issue.

2 participants