Merge pull request #4510 from emontnemery/hass_rework_light_status

Further improve Hass integration
This commit is contained in:
Theo Arends 2018-12-02 17:11:05 +01:00 committed by GitHub
commit b1a9de5a80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 8 deletions

View File

@ -72,7 +72,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t use_wifi_scan : 1; // bit 6 (v6.3.0.10) uint32_t use_wifi_scan : 1; // bit 6 (v6.3.0.10)
uint32_t use_wifi_rescan : 1; // bit 7 (v6.3.0.10) uint32_t use_wifi_rescan : 1; // bit 7 (v6.3.0.10)
uint32_t receive_raw : 1; // bit 8 (v6.3.0.11) uint32_t receive_raw : 1; // bit 8 (v6.3.0.11)
uint32_t hass_tele_as_result : 1; // bit 9 (v6.3.0.13) uint32_t hass_tele_on_power : 1; // bit 9 (v6.3.0.13)
uint32_t sleep_normal : 1; // bit 10 (v6.3.0.15) - SetOption60 - Enable normal sleep instead of dynamic sleep uint32_t sleep_normal : 1; // bit 10 (v6.3.0.15) - SetOption60 - Enable normal sleep instead of dynamic sleep
uint32_t spare11 : 1; uint32_t spare11 : 1;
uint32_t spare12 : 1; uint32_t spare12 : 1;

View File

@ -586,6 +586,9 @@ void MqttDataHandler(char* topic, byte* data, unsigned int data_len)
else if (CMND_STATE == command_code) { else if (CMND_STATE == command_code) {
mqtt_data[0] = '\0'; mqtt_data[0] = '\0';
MqttShowState(); MqttShowState();
if (Settings.flag3.hass_tele_on_power) {
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN);
}
} }
else if (CMND_SLEEP == command_code) { else if (CMND_SLEEP == command_code) {
if ((payload >= 0) && (payload < 251)) { if ((payload >= 0) && (payload < 251)) {
@ -1393,6 +1396,11 @@ void ExecuteCommandPower(byte device, byte state, int source)
#ifdef USE_KNX #ifdef USE_KNX
KnxUpdatePowerState(device, power); KnxUpdatePowerState(device, power);
#endif // USE_KNX #endif // USE_KNX
if (publish_power && Settings.flag3.hass_tele_on_power) {
mqtt_data[0] = '\0';
MqttShowState();
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN);
}
if (device <= MAX_PULSETIMERS) { // Restart PulseTime if powered On if (device <= MAX_PULSETIMERS) { // Restart PulseTime if powered On
SetPulseTimer(device -1, (((POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate) ? ~power : power) & mask) ? Settings.pulse_timer[device -1] : 0); SetPulseTimer(device -1, (((POWER_ALL_OFF_PULSETIME_ON == Settings.poweronstate) ? ~power : power) & mask) ? Settings.pulse_timer[device -1] : 0);
} }
@ -1691,11 +1699,7 @@ void PerformEverySecond(void)
mqtt_data[0] = '\0'; mqtt_data[0] = '\0';
MqttShowState(); MqttShowState();
if (Settings.flag3.hass_tele_as_result) {
MqttPublishPrefixTopic_P(STAT, S_RSLT_RESULT, MQTT_TELE_RETAIN);
} else {
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN); MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN);
}
mqtt_data[0] = '\0'; mqtt_data[0] = '\0';
if (MqttShowSensor()) { if (MqttShowSensor()) {

View File

@ -624,6 +624,11 @@ void LightPreparePower(void)
#ifdef USE_DOMOTICZ #ifdef USE_DOMOTICZ
DomoticzUpdatePowerState(light_device); DomoticzUpdatePowerState(light_device);
#endif // USE_DOMOTICZ #endif // USE_DOMOTICZ
if (Settings.flag3.hass_tele_on_power) {
mqtt_data[0] = '\0';
MqttShowState();
MqttPublishPrefixTopic_P(TELE, PSTR(D_RSLT_STATE), MQTT_TELE_RETAIN);
}
LightState(0); LightState(0);
} }

View File

@ -206,7 +206,8 @@ void HAssAnnounceRelayLight(void)
} }
GetPowerDevice(value_template, i, sizeof(value_template), Settings.flag.device_index_enable); GetPowerDevice(value_template, i, sizeof(value_template), Settings.flag.device_index_enable);
GetTopic_P(command_topic, CMND, mqtt_topic, value_template); GetTopic_P(command_topic, CMND, mqtt_topic, value_template);
GetTopic_P(state_topic, STAT, mqtt_topic, S_RSLT_RESULT); //GetTopic_P(state_topic, STAT, mqtt_topic, S_RSLT_RESULT);
GetTopic_P(state_topic, TELE, mqtt_topic, D_RSLT_STATE);
GetTopic_P(availability_topic, TELE, mqtt_topic, S_LWT); GetTopic_P(availability_topic, TELE, mqtt_topic, S_LWT);
FindPrefix(command_topic, state_topic, prefix); FindPrefix(command_topic, state_topic, prefix);
if (Settings.flag3.hass_short_discovery_msg) { if (Settings.flag3.hass_short_discovery_msg) {
@ -426,7 +427,7 @@ void HAssDiscovery(uint8_t mode)
if (Settings.flag.hass_discovery) { if (Settings.flag.hass_discovery) {
Settings.flag.mqtt_response = 0; // Response always as RESULT and not as uppercase command Settings.flag.mqtt_response = 0; // Response always as RESULT and not as uppercase command
Settings.flag.decimal_text = 1; // Respond with decimal color values Settings.flag.decimal_text = 1; // Respond with decimal color values
Settings.flag3.hass_tele_as_result = 1; // send tele/STATE message as stat/RESULT Settings.flag3.hass_tele_on_power = 1; // send tele/STATE message as stat/RESULT
// Settings.light_scheme = 0; // To just control color it needs to be Scheme 0 // Settings.light_scheme = 0; // To just control color it needs to be Scheme 0
if (!string_ends_with(Settings.mqtt_fulltopic, "%prefix%/")) { if (!string_ends_with(Settings.mqtt_fulltopic, "%prefix%/")) {
strncpy_P(Settings.mqtt_fulltopic, PSTR("%topic%/%prefix%/"), sizeof(Settings.mqtt_fulltopic)); strncpy_P(Settings.mqtt_fulltopic, PSTR("%topic%/%prefix%/"), sizeof(Settings.mqtt_fulltopic));