CyberDNS / Lupusec2Mqtt

Lupusec Alarm System to Mqtt
MIT License
11 stars 6 forks source link

Switches are no longer working #63

Closed christophgasser closed 2 months ago

christophgasser commented 10 months ago

Hi, since one of the latest HA updates (don't know exactly which one) the switches are no longer working. There is not significant information in the Lupusec2Mqtt Log. Even if I turn log level higher. Is this known? How can I contribute in fixing this issue?

BR C

christophgasser commented 10 months ago

For completeness: component is 3.1.3 HA is 2024.1.2

mucki12 commented 10 months ago

Same here with Osram Powerswitch (with Lupus2MQTT AND native Integration).

CyberDNS commented 10 months ago

Hi all, I checked the release notes and the breaking changes but couldn't find anything about a change related to this in a first sight. @christophgasser @mucki12 : And you didn't update your Lupusec alarm system neither?

The first thing we have to identify why this change in behavior happened. As nothing changed and you did not install any update on Lupusec2Mqtt side nor you did install an update on lupusec alarm system box AND also the native integration has the problem, I would think it is a problem on HA side in the switches component.

Br, David

mucki12 commented 10 months ago

@CyberDNS There was an Lupusec update to HPGW-G 0.0.3.6G. But I can't remember whether the switches stopped working before.

A snippet from the HA Log:

[16:32:15 ERR] Error during poll execution!
System.NullReferenceException: Object reference not set to an instance of an object.
   at Lupusec2Mqtt.Mqtt.Homeassistant.Devices.HumiditySensorFactory.GenerateDevicesAsync() in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Mqtt/Homeassistant/Devices/HumiditySensorFactory.cs:line 18
   at Lupusec2Mqtt.MainLoop.GetDevices() in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/MainLoop.cs:line 130
   at Lupusec2Mqtt.MainLoop.DoWork(Object state) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/MainLoop.cs:line 89
[16:32:15 INF] Value for topic homeassistant/switch/lupusec/ZS_b01a03/state on device ZS:b01a03 - Dachboden changed from OFF to ON
[16:32:17 INF] Value for topic homeassistant/switch/lupusec/ZS_b01a03/state on device ZS:b01a03 - Dachboden changed from ON to OFF
[16:32:42 ERR] Error calling GET http://192.168.2.50/:
Request:
Method: GET, RequestUri: 'http://192.168.2.50/', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  X-Token: !secret!
}
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 166
[16:32:42 INF] Command homeassistant/switch/lupusec/ZS_b01a03/set of device ZS:b01a03 - Dachboden executed with input ON
[16:32:42 ERR] Error calling POST http://192.168.2.50/action/deviceListGet:
Request:
Method: POST, RequestUri: 'http://192.168.2.50/action/deviceListGet', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  Authorization: Basic !secret!=
  X-Token: !secret!
}
System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 166
[16:32:42 INF] Value for topic homeassistant/switch/lupusec/ZS_b01a03/state on device ZS:b01a03 - Dachboden changed from OFF to ON
[16:32:43 INF] Value for topic homeassistant/switch/lupusec/ZS_b01a03/state on device ZS:b01a03 - Dachboden changed from ON to OFF
CyberDNS commented 10 months ago

@mucki12 What Lupusec version you have? I have the "LUPUS XT2 mit Dongle" and there the last version of the firmware is HPGW 0.0.3.6B.

Now I hope that, if really the problem is with the new firmware, that I will get that one on my system, because it will get very hard to debug this. 🤔

mucki12 commented 10 months ago

@CyberDNS I have the XT2 Plus (no Dongle needed).

Maybe a HA related problem? Found this with completely different switches: https://community.home-assistant.io/t/problem-with-toggle-switches/671782

Edit: Seems that there are even more problems with switches in HA > = 2024.1 https://github.com/AlexxIT/SonoffLAN/issues/1288 https://github.com/home-assistant/core/issues/106655

mucki12 commented 10 months ago

Reverted back to HA Core 2023.12.4 and switches are working again!

CyberDNS commented 10 months ago

Nice to hear that it is working again. Thanks @mucki12 for your research.

Will close the issue.

Br, David

mucki12 commented 10 months ago

Further testing: Updated to HA Core 2024.1.3 - switches are working, but just a short time period. After a while I got the same behavior as before. Switches turns immediately on/off - so no more function :-(

After restarting Lupus2MQTT (3.1.4) the switches are working for a period of time and a little bit later I got the same problem...

christophgasser commented 10 months ago

I currently have these version:

Core 2024.1.3 Supervisor 2023.12.1 Operating System 11.4 Frontend 20240104.0

Lupusec2Mqtt Edge 3.1.4

Switches are not working at all. No reaction. When I toggle one of the switches, there is nothing in the Lupusec2Mqtt log.

C

mucki12 commented 10 months ago

@christophgasser What happens after a restart of Lupus2MQTT: Check the log for this switch. Is it listet at all? Example:

[12:39:43 INF] Command homeassistant/switch/lupusec/ZS_xxxxx/set registered for device ZS:xxxxx - Dachboden
[12:39:43 INF] Device configured: ZS:XXXXX - Dachboden

Does the switch work right after a restart of Lupus2MQTT?

christophgasser commented 10 months ago

Yes.

[12:46:17 INF] Command homeassistant/switch/lupusec/ZS_xxxxx/set registered for device ZS:xxxx - Vorgarten [12:46:17 INF] Device configured: ZS:xxxxx - Vorgarten

[12:46:17 INF] Value for topic homeassistant/switch/lupusec/ZS_xxxxxx/state on device ZS:xxxxx - Vorgarten changed from null to OFF

[12:46:17 INF] Value for topic homeassistant/sensor/lupusec/ZS_xxxxx_power/state on device ZS:xxxxxx_power - Vorgarten - Power changed from null to 0.0

This is what I have in my logs.

christophgasser commented 10 months ago

For completeness: Currently the switch is OFF. HA GUI shows the switch ON.

CyberDNS commented 9 months ago

@CyberDNS There was an Lupusec update to HPGW-G 0.0.3.6G. But I can't remember whether the switches stopped working before.

A snippet from the HA Log:

[16:32:15 ERR] Error during poll execution!
System.NullReferenceException: Object reference not set to an instance of an object.
   at Lupusec2Mqtt.Mqtt.Homeassistant.Devices.HumiditySensorFactory.GenerateDevicesAsync() in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Mqtt/Homeassistant/Devices/HumiditySensorFactory.cs:line 18
   at Lupusec2Mqtt.MainLoop.GetDevices() in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/MainLoop.cs:line 130
   at Lupusec2Mqtt.MainLoop.DoWork(Object state) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/MainLoop.cs:line 89
[16:32:15 INF] Value for topic homeassistant/switch/lupusec/ZS_b01a03/state on device ZS:b01a03 - Dachboden changed from OFF to ON
[16:32:17 INF] Value for topic homeassistant/switch/lupusec/ZS_b01a03/state on device ZS:b01a03 - Dachboden changed from ON to OFF
[16:32:42 ERR] Error calling GET http://192.168.2.50/:
Request:
Method: GET, RequestUri: 'http://192.168.2.50/', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  X-Token: !secret!
}
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 166
[16:32:42 INF] Command homeassistant/switch/lupusec/ZS_b01a03/set of device ZS:b01a03 - Dachboden executed with input ON
[16:32:42 ERR] Error calling POST http://192.168.2.50/action/deviceListGet:
Request:
Method: POST, RequestUri: 'http://192.168.2.50/action/deviceListGet', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  Authorization: Basic !secret!=
  X-Token: !secret!
}
System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 166
[16:32:42 INF] Value for topic homeassistant/switch/lupusec/ZS_b01a03/state on device ZS:b01a03 - Dachboden changed from OFF to ON
[16:32:43 INF] Value for topic homeassistant/switch/lupusec/ZS_b01a03/state on device ZS:b01a03 - Dachboden changed from ON to OFF

Unfortunately I cannot reproduce the problem on my side, I am on the last HA OS and HA version, the difference is that the last version available on the my Lupusec is 0.0.3.6B. So I will need your support to find out the problem.

So first question is, do you have both the same exceptions in the log when the problem occurs? If yes, could you set Serilog.MinimumLevel.Default to Debug. The you should see the content of the messages that are send and received via Lupusec API. Because this part Unexpected character encountered while parsing value: < suggests that it is not json content that is send back but html.

Br, David

mucki12 commented 9 months ago

Hi David, i am now on HPGW-G 0.0.3.6I for Lupus and on 2024.2.2 for HA.

In the meantime, I no longer believe in a problem that only occurs with Lupus2MQTT. For testing purpose, I took in a new "powertest" switch. This can be switched as usual with Lupus, with Lupus2MQTT I have the same problem as already described.

But: The problem also occurs with the native Lupus integration. Here, too, you cannot switch with Home Assistant. Log is basically the same as before (sorry, I don't know where I can implement the detailed log as you mentioned).

[11:15:30 ERR] Error calling POST http://192.168.2.50/action/deviceListGet:
Request:
Method: POST, RequestUri: 'http://192.168.2.50/action/deviceListGet', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  Authorization: Basic xxx
  X-Token: xxx
}
System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 166
[11:15:30 ERR] Error calling GET http://192.168.2.50/:
Request:
Method: GET, RequestUri: 'http://192.168.2.50/', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  X-Token: xxx
}
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 166
[11:15:30 INF] Command homeassistant/switch/lupusec/ZS_b69603/set of device ZS:b69603 - powertest executed with input ON
[11:15:30 INF] Value for topic homeassistant/switch/lupusec/ZS_b69603/state on device ZS:b69603 - powertest changed from OFF to ON
[11:15:32 INF] Value for topic homeassistant/switch/lupusec/ZS_b69603/state on device ZS:b69603 - powertest changed from ON to OFF
[11:15:36 INF] Value for topic homeassistant/sensor/lupusec/ZS_7b7c01HUMIDITY/state on device ZS:7b7c01HUMIDITY - Temperatur Garten - Humidity changed from 74 to 73
[11:15:36 INF] Value for topic homeassistant/sensor/lupusec/ZS_7b7c01TEMPERATURE/state on device ZS:7b7c01TEMPERATURE - Temperatur Garten - Temperature changed from 7.84 to 8.36

Other components (contacts etc.) have no problem (neither with Lupus2MQTT nor with the native integration).

Sorry if this sounds pessimistic, but I might delete everything on the Lupus that is not security relevant. The Lupus is simply a (relatively weak) alarm system and not a HEMS system.

CyberDNS commented 9 months ago

Thanks @mucki12 for the info.

You can set the detailed log in the addon configuration, you should have this setting as the second last setting in the list or you can set it via YAML like this:

Serilog:MinimumLevel:Default: Debug
mucki12 commented 9 months ago

@CyberDNS Thanks - I set the level to debug and restarted Lupus2MQTT.

After that I was able to turn the switch in HA on and off again, which is normal as the problem only occurs after a certain time (don't know why? Token expired (but contacts work without problem) or does some component goes to sleep?).

So I waited again for a while and then tried the switch again and as usual it could no longer be switched.

Log right after the restart of Lupus2MQTT (successful switching):

[09:24:08 DBG] Request for POST /action/deviceSwitchPSSPost:
Request:
Method: POST, RequestUri: '/action/deviceSwitchPSSPost', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers:
{
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 27
}
Request body:
switch=1&pd=&id=ZS%3Ab69603
[09:24:08 INF] Value for topic homeassistant/switch/lupusec/ZS_b69603/state on device ZS:b69603 - powertest changed from OFF to ON
[09:24:09 DBG] Response for POST http://192.168.2.50/action/deviceSwitchPSSPost:
Response:
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Server: Mongoose
  Pragma: no-cache
  Cache-Control: no-cache
  Transfer-Encoding: chunked
  Expires: 0
  Content-Type: application/json; charset=utf-8
}
Response body:
{
  "result" : 1,
  "message" : "{WEB_MSG_SUBMIT_SUCCESS}"
}

[09:24:09 INF] Command homeassistant/switch/lupusec/ZS_b69603/set of device ZS:b69603 - powertest executed with input ON

.

Log after a certain time (round about 30 minutes) (unsuccessful switching):

[10:25:18 DBG] Request for POST /action/deviceSwitchPSSPost:
Request:
Method: POST, RequestUri: '/action/deviceSwitchPSSPost', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers:
{
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 27
}
Request body:
switch=1&pd=&id=ZS%3Ab69603
[10:25:18 DBG] Response for GET http://192.168.2.50/:
Response:
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Server: Mongoose
  Pragma: no-cache
  Cache-Control: no-cache
  Transfer-Encoding: chunked
  Content-Type: text/html; charset=utf-8
}
Response body:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head><title>Redirect to New Page</title><META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"><META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"><META HTTP-EQUIV="Expires" CONTENT="0"><script>
function redirect()
{
location.href='https:'+window.location.href.substring(window.location.protocol.length);
}
</script></head><body onload=redirect()></body></html>
[10:25:18 ERR] Error calling POST http://192.168.2.50/action/deviceListGet:
Request:
Method: POST, RequestUri: 'http://192.168.2.50/action/deviceListGet', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  Authorization: Basic anonymized
  X-Token: anonymized
}
System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 166
[10:25:18 ERR] Error calling GET http://192.168.2.50/:
Request:
Method: GET, RequestUri: 'http://192.168.2.50/', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  X-Token: anonymized
}
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 166
[10:25:18 INF] Command homeassistant/switch/lupusec/ZS_b69603/set of device ZS:b69603 - powertest executed with input ON
[10:25:19 INF] Value for topic homeassistant/switch/lupusec/ZS_b69603/state on device ZS:b69603 - powertest changed from OFF to ON
[10:25:20 INF] Value for topic homeassistant/switch/lupusec/ZS_b69603/state on device ZS:b69603 - powertest changed from ON to OFF
:
CyberDNS commented 9 months ago

Ok, it seems to be some mechanism to enforce https. The HTML contains some script to do a redirect enforcing https.

Can you give it a try with setting your Lupusec URL in the settings directly to https, please? Probably it will be happy when it directly communicates with https.

Br, David

mucki12 commented 9 months ago

@CyberDNS Of course - changed the Lupusec URL to https and will report back in one hour.

christophgasser commented 9 months ago

I have configured it with https since the beginning. Like: https://10.X.X.X If that is what you mean. But that does not help.

BR C

CyberDNS commented 9 months ago

@christophgasser , and you get the same log errors than @mucki12 ?

christophgasser commented 9 months ago

Sorry. I don't think so. I have set the Debug level to "information" for the integration. I don't get any warnings or error messages. At all. Just info like

[11:35:36 INF] Device configured: ZS:XXXXXXX_power - TV Verstärker - Power

or

[11:35:37 INF] Value for topic homeassistant/binary_sensor/lupusec/RF_XXXX/state on device RF:XXXXX - Schlafzimmer

Any other log I can check?

christophgasser commented 9 months ago

Not sure if that is relevant, but I am using "Lupusec2Mqtt Edge".

mucki12 commented 9 months ago

@CyberDNS One hour later... :-)

Thank you for your time looking into this, but unfortunately the switch no longer works after a certain waiting time, even with https...

Log round about 60 minutes after restart of Lupus2MQTT (trying to toggle - so several entries):

[12:02:36 DBG] Response for GET https://192.168.2.50/:
Response:
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Date: Sun, 25 Feb 2024 11:02:36 GMT
  ETag: "65db1e4c.11a"
  Connection: keep-alive
  Accept-Ranges: bytes
  Last-Modified: Sun, 25 Feb 2024 11:02:36 GMT
  Content-Type: text/html
  Content-Length: 282
}
Response body:
<!DOCTYPE html><html><head><title>Welcome</title><script type="text/javascript">document.location="/action/login"</script></head><body><noscript>JavaScript must be enabled.<br>However, it seems JavaScript is either disabled or not supported by your browser.</noscript></body></html>
[12:02:36 ERR] Error calling GET https://192.168.2.50/:
Request:
Method: GET, RequestUri: 'https://192.168.2.50/', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  X-Token: anonymized
}
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 166
[12:02:36 INF] Command homeassistant/switch/lupusec/ZS_b69603/set of device ZS:b69603 - powertest executed with input OFF
[12:02:36 ERR] Error calling POST https://192.168.2.50/action/deviceListGet:
Request:
Method: POST, RequestUri: 'https://192.168.2.50/action/deviceListGet', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  Authorization: anonymized
  X-Token: anonymized
}
System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 166
[12:02:36 INF] Value for topic homeassistant/switch/lupusec/ZS_b69603/state on device ZS:b69603 - powertest changed from ON to OFF
[12:02:37 INF] Value for topic homeassistant/switch/lupusec/ZS_b69603/state on device ZS:b69603 - powertest changed from OFF to ON
[12:02:39 DBG] Request for POST /action/deviceSwitchPSSPost:
Request:
Method: POST, RequestUri: '/action/deviceSwitchPSSPost', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers:
{
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 27
}
Request body:
switch=0&pd=&id=ZS%3Ab69603
[12:02:39 ERR] Error calling POST https://192.168.2.50/action/deviceGet:
Request:
Method: POST, RequestUri: 'https://192.168.2.50/action/deviceGet', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  Authorization: anonymized
  X-Token: anonymized
}
System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 166
[12:02:39 DBG] Response for GET https://192.168.2.50/:
Response:
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Date: Sun, 25 Feb 2024 11:02:40 GMT
  ETag: "65db1e50.11a"
  Connection: keep-alive
  Accept-Ranges: bytes
  Last-Modified: Sun, 25 Feb 2024 11:02:40 GMT
  Content-Type: text/html
  Content-Length: 282
}
Response body:
<!DOCTYPE html><html><head><title>Welcome</title><script type="text/javascript">document.location="/action/login"</script></head><body><noscript>JavaScript must be enabled.<br>However, it seems JavaScript is either disabled or not supported by your browser.</noscript></body></html>
[12:02:39 ERR] Error calling GET https://192.168.2.50/:
Request:
Method: GET, RequestUri: 'https://192.168.2.50/', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  X-Token: anonymized
}
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 166
[12:02:39 INF] Command homeassistant/switch/lupusec/ZS_b69603/set of device ZS:b69603 - powertest executed with input OFF
[12:02:40 ERR] Error during poll execution!
System.NullReferenceException: Object reference not set to an instance of an object.
   at Lupusec2Mqtt.Mqtt.Homeassistant.Devices.CoverFactory.GenerateDevicesAsync() in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Mqtt/Homeassistant/Devices/CoverFactory.cs:line 18
   at Lupusec2Mqtt.MainLoop.GetDevices() in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/MainLoop.cs:line 130
   at Lupusec2Mqtt.MainLoop.DoWork(Object state) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/MainLoop.cs:line 89
[12:02:40 INF] Value for topic homeassistant/switch/lupusec/ZS_b69603/state on device ZS:b69603 - powertest changed from ON to OFF
[12:02:41 INF] Value for topic homeassistant/switch/lupusec/ZS_b69603/state on device ZS:b69603 - powertest changed from OFF to ON

.

Edit: Regarding https there ist one config in the Lupus web interface: image

But I don't know if disabling this would help since now the Lupus2MQTT is already using https?

mucki12 commented 9 months ago

Manual regarding the last posted config: image

mucki12 commented 9 months ago

Next try:

Will be back in 45 minutes :-)

mucki12 commented 9 months ago

@CyberDNS After 45 minutes the switch works - one time :-( As I wrote this and less than 5 minutes later, I have tested the switch again - unfortunately again negative.

Log with unsuccessful switching :-( :

[13:34:15 DBG] Request for POST /action/deviceSwitchPSSPost:
Request:
Method: POST, RequestUri: '/action/deviceSwitchPSSPost', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers:
{
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 27
}
Request body:
switch=1&pd=&id=ZS%3Ab69603
[13:34:15 DBG] Response for GET http://192.168.2.50/:
Response:
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Date: Sun, 25 Feb 2024 12:34:15 GMT
  ETag: "65db33c7.11a"
  Connection: keep-alive
  Accept-Ranges: bytes
  Last-Modified: Sun, 25 Feb 2024 12:34:15 GMT
  Content-Type: text/html
  Content-Length: 282
}
Response body:
<!DOCTYPE html><html><head><title>Welcome</title><script type="text/javascript">document.location="/action/login"</script></head><body><noscript>JavaScript must be enabled.<br>However, it seems JavaScript is either disabled or not supported by your browser.</noscript></body></html>
[13:34:15 ERR] Error calling GET http://192.168.2.50/:
Request:
Method: GET, RequestUri: 'http://192.168.2.50/', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  X-Token: anonymized
}
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 166
[13:34:15 INF] Command homeassistant/switch/lupusec/ZS_b69603/set of device ZS:b69603 - powertest executed with input ON
[13:34:15 ERR] Error calling POST http://192.168.2.50/action/deviceListGet:
Request:
Method: POST, RequestUri: 'http://192.168.2.50/action/deviceListGet', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  Authorization: anonymized
  X-Token: anonymized
}
System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 166
[13:34:15 INF] Value for topic homeassistant/switch/lupusec/ZS_b69603/state on device ZS:b69603 - powertest changed from OFF to ON
[13:34:17 INF] Value for topic homeassistant/switch/lupusec/ZS_b69603/state on device ZS:b69603 - powertest changed from ON to OFF
mucki12 commented 9 months ago

Another test: HTTPS setting in the XT2 is still off and Lupusec2MQTT once again configured with https. Unfortunately the same result with the same log.

christophgasser commented 9 months ago

My Mosquitto broker log is full of:

2024-02-25 19:22:51: New connection from X.X.X.X:57978 on port 1883. 2024-02-25 19:22:51: Client Lupusec2Mqtt disconnected, not authorised.

BR C

CyberDNS commented 9 months ago

Hi all,

After reviewing the discussions, it seems the issue might be tied to a specific firmware version on the Lupusec system. Unfortunately, I'm unable to replicate this as my setup is on an older firmware, and I don't have access to the newer hardware for testing.

Given my current time constraints and hardware limitations, I'm hoping someone with the new hardware can dive deeper into this issue. If you're able to investigate and perhaps propose a solution via a pull request, it would greatly benefit the project.

Otherwise, we may need to await insights or solutions shared in similar open-source projects that we can adapt.

Appreciate your understanding and any contributions you can make.

Best regards, David

christophgasser commented 9 months ago

Hi David,

I have an IT background and also do some developement (mostly databases and C#). Although I have never done anythig with Pyton, etc. But my biggest issue is to setup and configure a dev environment to do the debugging and testing. I do have a XT1 Plus and a XT2 Plus available for testing.

If you could help me setting up the dev environment, I would be more than happy to support.

BR C

CyberDNS commented 9 months ago

Hi Christoph,

I appreciate that you are happy to help. I can assist you in getting your dev environment up and running. The code is written in C#, no python needed.

  1. Install Visual Studio 2022 Community Edition
  2. Fork this repository into your github account (You have this button on the top right side near the stars button)
  3. Clone the forked repository from your account in Visual Studio (in one of the first windows of Visual Studio you can clone a repository, normally you can select there to clone from a Github account)
  4. Have a look into the CONTRIBUTING.md to setup the settings to connect to your MQTT and LUPUSEC. !! You have to put those settings in the UserSecrets file to avoid pushing them to Github !! You can do this by right clicking on the project, then select User Secrets to open the file.
  5. Then run the solution and check if it connects to your LUPUSEC and MQTT
  6. A lot of reverse engineering can be done using the developer tools in your browser when opening the LUPUSEC page (Network tab)
  7. When you have finished you can commit and push to your Github repo and open a Pull Request

If you have further questions or problems, I am glad to help out where I can.

Br, David

christophgasser commented 9 months ago

Thank you David! I will try my best but wont have time before next week. Keep you updated!

christophgasser commented 8 months ago

Started testing. I picked one particular switch to check. This switch hast state ON in HA (the switch was ON when the problems started and it remained ON). In VS the switch has state OFF. I checked in class "MainLoop" within function "UpdateStates".

For completeness: The switch is OFF. On the Lupus.

Where / how can I test how the value is passed to HA? How to check to toggle a switch?

BR C

christophgasser commented 8 months ago

When executing this line of code:

_lupusecService.SetSwitch("ZS:XXX", true); _lupusecService.SetSwitch("ZS:XXX", false);

I can successfully switch on/off the switch. As far as I can tell, the component / classes that are communicating with the Lupus are doing fine.

But as mentioned in my last post, I do not know how to check the communication with HA.

BR C

CyberDNS commented 8 months ago

Hi @christophgasser , You can use a tool like MQTTExplorer to inspect what is written into MQTT by Lupusec2Mqtt or HA. This can help to identify on which side the problem occurs.

Br, David

CyberDNS commented 8 months ago

For you information, I have installed a firmware update on my XT2 just now, probably this will show the same problem so that I can debug what is happening.

Will see what happens.

CyberDNS commented 8 months ago

Hi @christophgasser,

Did you already find something for this issue. Probably you have already seen the other issue #74 that was related to TLS/SSL that is now resolved in Edge v3.3.1. You can give it a try to see if your problem was probably related to that one.

Br, David

christophgasser commented 8 months ago

Dear David,

Thank you for fixing the problem! Working on my side as well now. But I had to reinstall and reconfigure the MQQT Broker as well as the Lupus add on. Not sure if that as due to playing around and trying to fix the issue myself.

BR Christoph


Christoph Gasser, MSc Stranto Business Solutions GmbH Büro: Leopold-Gattringerstraße 121, 2345 Brunn am Gebirge, Austria Post & Rechnung: Schirgenwaldallee 7, 2380 Perchtoldsdorf, Austria Tel.: +43 / 1 / 236 82 96 - 16 Mob.: +43 / 664 / 5130386 Email & Teams: @.**@.> Internet: http://www.stranto.com/<blocked::http://www.stranto.com/>

Von: David Ney @.> Gesendet: Samstag, 23. März 2024 14:49 An: CyberDNS/Lupusec2Mqtt @.> Cc: Gasser Christoph @.>; Mention @.> Betreff: Re: [CyberDNS/Lupusec2Mqtt] Switches are no longer working (Issue #63)

Hi @christophgasserhttps://github.com/christophgasser,

Did you already find something for this issue. Probably you have already seen the other issue #74https://github.com/CyberDNS/Lupusec2Mqtt/issues/74 that was related to TLS/SSL that is now resolved in Edge v3.3.1. You can give it a try to see if your problem was probably related to that one.

Br, David

— Reply to this email directly, view it on GitHubhttps://github.com/CyberDNS/Lupusec2Mqtt/issues/63#issuecomment-2016500432, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ABVNGICYYCECVFW6PUGQF7LYZWB3FAVCNFSM6AAAAABBRUYIPSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMJWGUYDANBTGI. You are receiving this because you were mentioned.Message ID: @.***>

christophgasser commented 8 months ago

@CyberDNS : If you need some Lupus devices, just let me know. Can't write more details here ... ;-)

CyberDNS commented 8 months ago

@CyberDNS : If you need some Lupus devices, just let me know. Can't write more details here ... ;-)

@christophgasser : You can contact me (in german 😉) on the following mail cyberdns.e3ccb2fc@outlook.com, then you can explain me what you have in mind 🙂.

Br, David

sensiminded commented 3 months ago

Hi @CyberDNS ,

I have searched a lot since I installed HA and connected it with mit XT2+, but I am still running in the issue described by @mucki12 . The log seen in my HA is the same as for him. Everything is working fine after a restart of the Lupusec2Mqtt Edge AddIn, but after a while the switch state can not be changed from HA. Status updates from sensors and switches are still working without any issue.

Setup: XT2 Plus SW 0.0.3.6N Lupusec2Mqtt Edge Current version: 3.3.2 Core 2024.8.1 Supervisor 2024.08.0 Operating System 12.4 Frontend 20240809.0

Are any news available on this?

Maybe just as a side question I was no able to answer. What is the difference between the normal and the edge AddIn?

BR, Alex

sensiminded commented 3 months ago

I collected logs for the switch working and not working state. I restarted the Add In yesterday evening (9PM?) for enabling debug log. It was not working around 16-17 h later. The log between correct function and disturbed function shows nothing.

Hope you can help.

switch working:

[06:29:02 DBG] Request for POST /action/deviceSwitchPSSPost:
Request:
Method: POST, RequestUri: '/action/deviceSwitchPSSPost', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers:
{
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 27
}
Request body:
switch=1&pd=&id=ZS%3A50b401
[06:29:04 INF] Value for topic homeassistant/switch/lupusec/ZS_50b401/state on device ZS:50b401 - Garten Strom changed from OFF to ON
[06:29:04 DBG] Response for POST https://192.168.178.50/action/deviceSwitchPSSPost:
Response:
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Server: Mongoose
  Pragma: no-cache
  Cache-Control: no-cache
  Transfer-Encoding: chunked
  Expires: 0
  Content-Type: application/json; charset=utf-8
}
Response body:
{
  "result" : 1,
  "message" : "{WEB_MSG_SUBMIT_SUCCESS}"
}

[06:29:04 INF] Command homeassistant/switch/lupusec/ZS_50b401/set of device ZS:50b401 - Garten Strom executed with input ON
[06:29:20 DBG] Request for POST /action/deviceSwitchPSSPost:
Request:
Method: POST, RequestUri: '/action/deviceSwitchPSSPost', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers:
{
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 27
}
Request body:
switch=0&pd=&id=ZS%3A50b401
[06:29:21 INF] Value for topic homeassistant/switch/lupusec/ZS_50b401/state on device ZS:50b401 - Garten Strom changed from ON to OFF
[06:29:21 DBG] Response for POST https://192.168.178.50/action/deviceSwitchPSSPost:
Response:
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Server: Mongoose
  Pragma: no-cache
  Cache-Control: no-cache
  Transfer-Encoding: chunked
  Expires: 0
  Content-Type: application/json; charset=utf-8
}
Response body:
{
  "result" : 1,
  "message" : "{WEB_MSG_SUBMIT_SUCCESS}"
}

[06:29:21 INF] Command homeassistant/switch/lupusec/ZS_50b401/set of device ZS:50b401 - Garten Strom executed with input OFF

switch not working:

[14:50:41 DBG] Request for POST /action/deviceSwitchPSSPost:
Request:
Method: POST, RequestUri: '/action/deviceSwitchPSSPost', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers:
{
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 27
}
Request body:
switch=1&pd=&id=ZS%3A50b401
[14:50:41 DBG] Response for GET https://192.168.178.50/:
Response:
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Date: Wed, 14 Aug 2024 12:50:41 GMT
  ETag: "66bca821.11a"
  Connection: keep-alive
  Accept-Ranges: bytes
  Last-Modified: Wed, 14 Aug 2024 12:50:41 GMT
  Content-Type: text/html
  Content-Length: 282
}
Response body:
<!DOCTYPE html><html><head><title>Welcome</title><script type="text/javascript">document.location="/action/login"</script></head><body><noscript>JavaScript must be enabled.<br>However, it seems JavaScript is either disabled or not supported by your browser.</noscript></body></html>
[14:50:41 ERR] Error calling GET https://192.168.178.50/:
Request:
Method: GET, RequestUri: 'https://192.168.178.50/', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  X-Token: ersetzt
}
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.JsonReader.ReadAndMoveToContent()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 159
[14:50:41 INF] Command homeassistant/switch/lupusec/ZS_50b401/set of device ZS:50b401 - Garten Strom executed with input ON
[14:50:41 ERR] Error calling POST https://192.168.178.50/action/deviceListGet:
Request:
Method: POST, RequestUri: 'https://192.168.178.50/action/deviceListGet', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  Authorization: Basic ersetzt==
  X-Token: ersetzt
}
System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
   at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 148
[14:50:42 INF] Value for topic homeassistant/switch/lupusec/ZS_50b401/state on device ZS:50b401 - Garten Strom changed from OFF to ON
[14:50:43 INF] Value for topic homeassistant/switch/lupusec/ZS_50b401/state on device ZS:50b401 - Garten Strom changed from ON to OFF
CyberDNS commented 3 months ago

Hi Alex,

I checked you logs and it seems that at some point the authorization is lost, I added some code to get a new token at the moment this happens.

I published a new Edge version that contains this change (v3.3.3). And there you have the explanation about the difference of the "normal" and the "edge" version ;), the edge version is used to test new features or fixes, and from time to time I publish a new "normal" or stable version when those features and fixes are well approved. This reminds me that I should publish a new "normal" version again. So at the moment I get your feedback if everything works fine, I will publish a new normal version, you are free to switch to that version or stay on the edge one.

Br, David

sensiminded commented 3 months ago

Hi David,

I assumed the same with the lost authentication reading the logs, but I am no programmer so I was not sure. ;-) Therefore I am really glad that the logs provided useful information to you. I just upgraded to 3.3.3 and will report back the next days, if this is fixed.

Thank you, Alex

sensiminded commented 3 months ago

Hi David,

yesterday I got a failed switch control. For me the log look like before. But there was one difference, 3 minutes later it worked without any additional manipulation.

I can not identify your new programmed login, but it seems to work. Over the afternoon I cannot see the complete logging, because there are several automated switch actions and the log is overwritten. I will further check.

One question, if you see in the log, that your fix with reauthorization worked, will it be possible in case of the error to repeat the task? No switch action will be lost if this is possible.

And for sure the logs.

not working:

[22:52:52 DBG] Request for POST /action/deviceSwitchPSSPost:
Request:
Method: POST, RequestUri: '/action/deviceSwitchPSSPost', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers:
{
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 27
}
Request body:
switch=0&pd=&id=ZS%3A50b401
[22:52:52 DBG] Response for GET https://192.168.178.50/:
Response:
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Date: Sun, 18 Aug 2024 20:52:52 GMT
  ETag: "66c25f24.11a"
  Connection: keep-alive
  Accept-Ranges: bytes
  Last-Modified: Sun, 18 Aug 2024 20:52:52 GMT
  Content-Type: text/html
  Content-Length: 282
}
Response body:
<!DOCTYPE html><html><head><title>Welcome</title><script type="text/javascript">document.location="/action/login"</script></head><body><noscript>JavaScript must be enabled.<br>However, it seems JavaScript is either disabled or not supported by your browser.</noscript></body></html>
[22:52:52 ERR] Error calling GET https://192.168.178.50/:
Request:
Method: GET, RequestUri: 'https://192.168.178.50/', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  X-Token: ersetzt
}
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
   at Newtonsoft.Json.JsonTextReader.ParseValue()
   at Newtonsoft.Json.JsonReader.ReadAndMoveToContent()
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 159
[22:52:52 INF] Command homeassistant/switch/lupusec/ZS_50b401/set of device ZS:50b401 - Garten Strom executed with input OFF
[22:52:54 INF] Value for topic homeassistant/switch/lupusec/ZS_50b401/state on device ZS:50b401 - Garten Strom changed from ON to OFF
[22:52:54 INF] Value for topic homeassistant/switch/lupusec/ZS_50b401/state on device ZS:50b401 - Garten Strom changed from OFF to ON

switch working:

[22:55:51 DBG] Request for POST /action/deviceSwitchPSSPost:
Request:
Method: POST, RequestUri: '/action/deviceSwitchPSSPost', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers:
{
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 27
}
Request body:
switch=0&pd=&id=ZS%3A50b401
[22:55:52 INF] Value for topic homeassistant/switch/lupusec/ZS_50b401/state on device ZS:50b401 - Garten Strom changed from ON to OFF
[22:55:53 DBG] Response for POST https://192.168.178.50/action/deviceSwitchPSSPost:
Response:
StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
  Server: Mongoose
  Pragma: no-cache
  Cache-Control: no-cache
  Transfer-Encoding: chunked
  Expires: 0
  Content-Type: application/json; charset=utf-8
}
Response body:
{
  "result" : 1,
  "message" : "{WEB_MSG_SUBMIT_SUCCESS}"
}

[22:55:53 INF] Command homeassistant/switch/lupusec/ZS_50b401/set of device ZS:50b401 - Garten Strom executed with input OFF

Best regards, Alex

CyberDNS commented 3 months ago

Hi Alex,

I published just now a new version that tries to do the refresh already when it fails the first time (when the html page is returned). Probably this will resolve the problem so that the switch will continue to work. You should now see also a log entry when the retry happens.

The version is Edge 3.3.4.

Happy testing, David

sensiminded commented 2 months ago

Hey David,

thanks for your updates on this.

I have just seen, that the switches are not working since yesterday, but I cannot say exactly when, because the log goes not that far.

Actual log for a switch action:

[07:31:31 DBG] Request for POST /action/deviceSwitchPSSPost:
Request:
Method: POST, RequestUri: '/action/deviceSwitchPSSPost', Version: 1.1, Content: System.Net.Http.FormUrlEncodedContent, Headers:
{
  Content-Type: application/x-www-form-urlencoded
  Content-Length: 27
}
Request body:
switch=1&pd=&id=ZS%3A792701
[07:31:31 ERR] Error calling GET https://192.168.178.50/:
Request:
Method: GET, RequestUri: 'https://192.168.178.50/', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  X-Token: anonym
}
System.ArgumentNullException: Value cannot be null. (Parameter 'logger')
   at System.ThrowHelper.Throw(String paramName)
   at Microsoft.Extensions.Logging.LoggerExtensions.Log(ILogger logger, LogLevel logLevel, EventId eventId, Exception exception, String message, Object[] args)
   at Microsoft.Extensions.Logging.LoggerExtensions.Log(ILogger logger, LogLevel logLevel, String message, Object[] args)
   at Lupusec2Mqtt.Lupusec.LupusecTokenHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecTokenHandler.cs:line 44
   at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.<SendCoreAsync>g__Core|5_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 147
[07:31:31 INF] Command homeassistant/switch/lupusec/ZS_792701/set of device ZS:792701 - Warmwasser executed with input ON
[07:31:32 ERR] Error calling POST https://192.168.178.50/action/deviceListGet:
Request:
Method: POST, RequestUri: 'https://192.168.178.50/action/deviceListGet', Version: 1.1, Content: <null>, Headers:
{
  Accept: application/json
  Authorization: Basic anonym
  X-Token: anonym
}
System.ArgumentNullException: Value cannot be null. (Parameter 'logger')
   at System.ThrowHelper.Throw(String paramName)
   at Microsoft.Extensions.Logging.LoggerExtensions.Log(ILogger logger, LogLevel logLevel, EventId eventId, Exception exception, String message, Object[] args)
   at Microsoft.Extensions.Logging.LoggerExtensions.Log(ILogger logger, LogLevel logLevel, String message, Object[] args)
   at Lupusec2Mqtt.Lupusec.LupusecTokenHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecTokenHandler.cs:line 44
   at Microsoft.Extensions.Http.Logging.LoggingScopeHttpMessageHandler.<SendCoreAsync>g__Core|5_0(HttpRequestMessage request, Boolean useAsync, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
   at Lupusec2Mqtt.Lupusec.LupusecService.SendRequest[T](HttpRequestMessage request, LogLevel logLevel) in /src/Lupusec2Mqtt/src/Lupusec2Mqtt/Lupusec/LupusecService.cs:line 147
[07:31:32 INF] Value for topic homeassistant/switch/lupusec/ZS_792701/state on device ZS:792701 - Warmwasser changed from OFF to ON
[07:31:33 INF] Value for topic homeassistant/switch/lupusec/ZS_792701/state on device ZS:792701 - Warmwasser changed from ON to OFF

Bes regards, Alex

CyberDNS commented 2 months ago

Hi Alex @sensiminded ,

Sorry for that, it was a bug that I introduced during the code changes to try to make your switches (always) work. The bug should be fixed now and you should see a log entry when the token is refreshed.

It is Edge version 3.3.5.

Br, David

CyberDNS commented 2 months ago

Hi @sensiminded,

Does it work now or do you have still problems? Otherwise I will close the issue an generate a new stable version.

Br, David