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

Switches are no longer working #63

Closed
christophgasser opened this issue Jan 8, 2024 · 41 comments
Closed

Switches are no longer working #63

christophgasser opened this issue Jan 8, 2024 · 41 comments
Labels
bug Something isn't working

Comments

@christophgasser
Copy link

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
Copy link
Author

For completeness: component is 3.1.3
HA is 2024.1.2

@mucki12
Copy link

mucki12 commented Jan 9, 2024

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

@CyberDNS
Copy link
Owner

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
Copy link

mucki12 commented Jan 13, 2024

@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
Copy link
Owner

@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
Copy link

mucki12 commented Jan 13, 2024

@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
AlexxIT/SonoffLAN#1288
home-assistant/core#106655

@mucki12
Copy link

mucki12 commented Jan 13, 2024

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

@CyberDNS
Copy link
Owner

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

Will close the issue.

Br,
David

@mucki12
Copy link

mucki12 commented Jan 16, 2024

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
Copy link
Author

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
Copy link

mucki12 commented Jan 17, 2024

@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
Copy link
Author

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
Copy link
Author

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

@CyberDNS
Copy link
Owner

@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
Copy link

mucki12 commented Feb 24, 2024

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
Copy link
Owner

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
Copy link

mucki12 commented Feb 25, 2024

@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
Copy link
Owner

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
Copy link

mucki12 commented Feb 25, 2024

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

@christophgasser
Copy link
Author

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
Copy link
Owner

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

@christophgasser
Copy link
Author

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
Copy link
Author

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

@mucki12
Copy link

mucki12 commented Feb 25, 2024

@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
Copy link

mucki12 commented Feb 25, 2024

Manual regarding the last posted config:
image

@mucki12
Copy link

mucki12 commented Feb 25, 2024

Next try:

  • deactivated the "Automatische HTTPS Umleitung" and restarted XT2
  • switched back to http and restarted Lupus2MQTT

Will be back in 45 minutes :-)

@mucki12
Copy link

mucki12 commented Feb 25, 2024

@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
Copy link

mucki12 commented Feb 25, 2024

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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

@christophgasser
Copy link
Author

christophgasser commented Mar 5, 2024

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
Copy link
Author

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
Copy link
Owner

CyberDNS commented Mar 7, 2024

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
Copy link
Owner

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 CyberDNS added the bug Something isn't working label Mar 17, 2024
@CyberDNS
Copy link
Owner

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
Copy link
Author

christophgasser commented Mar 24, 2024 via email

@christophgasser
Copy link
Author

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

@CyberDNS
Copy link
Owner

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants