KartoffelToby / better_thermostat

This custom component for Home Assistant will add crucial features to your climate-controlling TRV (Thermostatic Radiator Valves) to save you the work of creating automations to make it smart. It combines a room-temperature sensor, window/door sensors, weather forecasts, or an ambient temperature probe to decide when it should call for heat and automatically calibrate your TRVs to fix the imprecise measurements taken in the radiator's vicinity.
https://better-thermostat.org
GNU Affero General Public License v3.0
718 stars 124 forks source link

BT stopped working with 1.5.1, Invalid state length #1357

Open gmdfalk opened 2 months ago

gmdfalk commented 2 months ago

Prerequisites

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2024.5.4",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.12.2",
    "docker": true,
    "arch": "aarch64",
    "timezone": "Europe/Berlin",
    "os_name": "Linux",
    "os_version": "6.6.28-haos-raspi",
    "supervisor": "2024.05.1",
    "host_os": "Home Assistant OS 12.3",
    "docker_version": "25.0.5",
    "chassis": "embedded",
    "run_as_root": true
  },
  "custom_components": {
    "better_thermostat": {
      "documentation": "https://github.com/KartoffelToby/better_thermostat",
      "version": "1.5.1",
      "requirements": []
    },
    "hacs": {
      "documentation": "https://hacs.xyz/docs/configuration/start",
      "version": "1.34.0",
      "requirements": [
        "aiogithubapi>=22.10.1"
      ]
    }
  },
  "integration_manifest": {
    "domain": "better_thermostat",
    "name": "Better Thermostat",
    "after_dependencies": [
      "climate"
    ],
    "codeowners": [
      "@kartoffeltoby"
    ],
    "config_flow": true,
    "dependencies": [
      "climate",
      "recorder"
    ],
    "documentation": "https://github.com/KartoffelToby/better_thermostat",
    "iot_class": "local_push",
    "issue_tracker": "https://github.com/KartoffelToby/better_thermostat/issues",
    "requirements": [],
    "version": "1.5.1",
    "is_built_in": false
  },
  "data": {
    "info": {
      "name": "better_thermostat_dg_ankleide",
      "temperature_sensor": "sensor.temperature_sensor_dg_ankleide_temperature",
      "off_temperature": 18,
      "tolerance": 0.5,
      "target_temp_step": 0.0,
      "humidity_sensor": "sensor.temperature_sensor_dg_ankleide_humidity",
      "outdoor_sensor": "sensor.temperature_sensor_eg_terrasse_temperature",
      "window_sensors": "binary_sensor.contact_sensor_dg_ankleide_contact",
      "weather": "weather.openweathermap",
      "window_off_delay": 30,
      "window_off_delay_after": 30,
      "cooler": null,
      "model": "TRVZB"
    },
    "thermostat": {
      "climate.thermostat_dg_ankleide": {
        "name": "thermostat.dg_ankleide",
        "state": "off",
        "attributes": {
          "hvac_modes": [
            "off",
            "auto",
            "heat"
          ],
          "min_temp": 4.0,
          "max_temp": 35.0,
          "target_temp_step": 0.5,
          "current_temperature": 22.1,
          "temperature": 7.0,
          "hvac_action": "idle",
          "battery": 97,
          "battery_low": null,
          "child_lock": "UNLOCK",
          "closing_steps": 354,
          "frost_protection_temperature": 7,
          "idle_steps": 243,
          "linkquality": 94,
          "local_temperature": 22.1,
          "local_temperature_calibration": -0.2,
          "occupied_heating_setpoint": 7,
          "open_window": "OFF",
          "running_state": "idle",
          "system_mode": "off",
          "update": {
            "installed_version": 4357,
            "latest_version": 4357,
            "state": "idle"
          },
          "update_available": null,
          "valve_closing_degree": 100,
          "valve_closing_limit_voltage": 2700,
          "valve_motor_running_voltage": 1338,
          "valve_opening_degree": 100,
          "valve_opening_limit_voltage": 1303,
          "weekly_schedule": {
            "friday": "00:00/16 07:00/19 10:00/16 10:00/16 17:00/19 23:00/16",
            "monday": "00:00/16 07:00/19 10:00/16 10:00/16 17:00/19 23:00/16",
            "saturday": "00:00/16 07:00/19 10:00/19 10:00/19 10:00/19 23:00/16",
            "sunday": "00:00/16 07:00/19 10:00/19 10:00/19 10:00/19 23:00/16",
            "thursday": "00:00/16 07:00/19 10:00/16 10:00/16 17:00/19 23:00/16",
            "tuesday": "00:00/16 07:00/19 10:00/16 10:00/16 17:00/19 23:00/16",
            "wednesday": "00:00/16 07:00/19 10:00/16 10:00/16 17:00/19 23:00/16"
          },
          "friendly_name": "thermostat.dg_ankleide",
          "supported_features": 385
        },
        "bt_config": {
          "calibration": "target_temp_based",
          "calibration_mode": "fix_calibration",
          "protect_overheating": false,
          "no_off_system_mode": false,
          "heat_auto_swapped": false,
          "child_lock": false,
          "homaticip": false
        },
        "bt_adapter": "mqtt",
        "bt_integration": "mqtt",
        "model": "TRVZB"
      }
    },
    "external_temperature_sensor": {
      "entity_id": "sensor.temperature_sensor_dg_ankleide_temperature",
      "state": "18.23",
      "attributes": {
        "state_class": "measurement",
        "battery": 83,
        "humidity": 50.84,
        "linkquality": 83,
        "power_outage_count": 13,
        "pressure": 1010,
        "temperature": 18.23,
        "voltage": 2975,
        "unit_of_measurement": "\u00b0C",
        "device_class": "temperature",
        "friendly_name": "temperature_sensor.dg_ankleide Temperature"
      },
      "last_changed": "2024-05-18T04:11:05.300950+00:00",
      "last_reported": "2024-05-18T04:11:05.300950+00:00",
      "last_updated": "2024-05-18T04:11:05.300950+00:00",
      "context": {
        "id": "01HY4YAV6MVZ6RHRSGBKEGGM7R",
        "parent_id": null,
        "user_id": null
      }
    },
    "window_sensor": {
      "entity_id": "binary_sensor.contact_sensor_dg_ankleide_contact",
      "state": "off",
      "attributes": {
        "battery": 100,
        "contact": true,
        "device_temperature": 25,
        "linkquality": 123,
        "power_outage_count": 108,
        "trigger_count": 0,
        "voltage": 3015,
        "device_class": "door",
        "friendly_name": "contact_sensor.dg_ankleide Door"
      },
      "last_changed": "2024-05-18T04:11:04.293851+00:00",
      "last_reported": "2024-05-18T04:11:04.293851+00:00",
      "last_updated": "2024-05-18T04:11:04.293851+00:00",
      "context": {
        "id": "01HY4YAT75XAV23ZBGF08A2FS6",
        "parent_id": null,
        "user_id": null
      }
    }
  }
}

Description

BT stopped working for me a few weeks ago. Around that time i updated BT to 1.5.1 and HA Core 2024.5.x. So either of those updates might have caused this. Downgrading to BT 1.5.0 works for me to restore functionality, although the error still appears. I've reset the _local_temperature_calibration entity to 0, no idea how they ended up with values out of range.

These are the BT error logs i see in the system logs:

Logger: homeassistant.helpers.entity
Source: helpers/entity.py:1203
First occurred: May 18, 2024 at 06:11:04 (696 occurrences)
Last logged: 10:27:55

Failed to set state for sensor.thermostat_dg_bad_weekly_schedule, fall back to unknown
Failed to set state for sensor.thermostat_eg_wohnzimmer_couch_weekly_schedule, fall back to unknown
Failed to set state for sensor.thermostat_dg_schlafzimmer_weekly_schedule, fall back to unknown
Failed to set state for sensor.thermostat_eg_eingang_weekly_schedule, fall back to unknown
Failed to set state for sensor.thermostat_og_bad_weekly_schedule, fall back to unknown
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1203, in _async_write_ha_state
    hass.states.async_set(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2310, in async_set
    state = State(
            ^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 1788, in __init__
    validate_state(state)
  File "/usr/src/homeassistant/homeassistant/core.py", line 228, in validate_state
    raise InvalidStateError(
homeassistant.exceptions.InvalidStateError: Invalid state with length 477. State max length is 255 characters.
Logger: homeassistant.components.mqtt.number
Source: components/mqtt/number.py:195
integration: MQTT (documentation, issues)
First occurred: May 18, 2024 at 06:11:04 (279 occurrences)
Last logged: 10:21:30

Invalid value for number.thermostat_eg_wohnzimmer_couch_local_temperature_calibration: 11.6 (range -7.0 - 7.0)
Invalid value for number.thermostat_dg_schlafzimmer_local_temperature_calibration: 11.6 (range -7.0 - 7.0)
Invalid value for number.thermostat_dg_bad_local_temperature_calibration: 11.6 (range -7.0 - 7.0)

I also get the warning reporter here: https://github.com/KartoffelToby/better_thermostat/issues/1347

Versions

BT 1.5.1 Core 2024.5.4 Operating System 12.3

Loeffelmaster commented 2 months ago

I have the same Problem, haven't checked my thermostat and it shows unavailable even though it is available in Z2M. I checked the data and it failed at 9th of may, when I updated to 2024.5.0. As there where many changes in MQTT and since then every version corrected values in MQTT (same timings not working correctly) I haven't updated further more until they fix the MQTT timing.

Could that be correlated?

The firmware version of my Sonoff TRVZB is 1.1.5

hilburn commented 1 month ago

You need to disable the weekly_schedule sensor for your TRV and it fixes the behaviour I've tried talking to both the z2m and homeassistant people and neither of them accept responsibility for fixing this

Loeffelmaster commented 1 month ago

You need to disable the weekly_schedule sensor for your TRV and it fixes the behaviour I've tried talking to both the z2m and homeassistant people and neither of them accept responsibility for fixing this

I have disabled the weekly_schedule sensor, afterwards I fully restarted my HA computer. The thermostat is still unavailable. How can I make it available again? Disabling the sensor isn't enough it seems.

Ey3scr34m commented 1 month ago

You need to disable the weekly_schedule sensor for your TRV and it fixes the behaviour I've tried talking to both the z2m and homeassistant people and neither of them accept responsibility for fixing this

I have the same problem. Where do I disable the weekly_schedule?

Loeffelmaster commented 1 month ago

You need to disable the weekly_schedule sensor for your TRV and it fixes the behaviour I've tried talking to both the z2m and homeassistant people and neither of them accept responsibility for fixing this

I have the same problem. Where do I disable the weekly_schedule?

Settings => Integrations, etc. => Entities Search for weekly and you will find it.

Loeffelmaster commented 1 month ago

You need to disable the weekly_schedule sensor for your TRV and it fixes the behaviour I've tried talking to both the z2m and homeassistant people and neither of them accept responsibility for fixing this

I have the same problem. Where do I disable the weekly_schedule?

But for me that didn't changed anything, I've even reconfigured BetterThermostat nothing changes. New start, whatever I do, the TRV stays unavailable in BT. In Z2M it is online and can be controlled without a problem. So I hope for you, that it helps in your case. On my system it didn't change anything.

Ey3scr34m commented 1 month ago

You need to disable the weekly_schedule sensor for your TRV and it fixes the behaviour I've tried talking to both the z2m and homeassistant people and neither of them accept responsibility for fixing this

I have the same problem. Where do I disable the weekly_schedule?

Settings => Integrations, etc. => Entities Search for weekly and you will find it.

Well that's what I did before asking here and I couldn't find anything. Maybe my TRVs don't have it? I got the Bosch TRV II.

stevenbuehner commented 1 month ago

You need to disable the weekly_schedule sensor for your TRV and it fixes the behaviour I've tried talking to both the z2m and homeassistant people and neither of them accept responsibility for fixing this

I have the same problem. Where do I disable the weekly_schedule?

Settings => Integrations, etc. => Entities Search for weekly and you will find it.

Well that's what I did before asking here and I couldn't find anything. Maybe my TRVs don't have it? I got the Bosch TRV II.

I am having exact the same problems. Also with Bosch TRV 2.

Unclezz commented 9 hours ago

So, today I played a bit with my Sonoff TRVZB. They are running firmware 1.1.5. BT is version 1.6.0.

Basically whatever you do in HA through BT is not reflected to the valves. And viceversa, if you change something on the valve, it reflects in the HA UI, but after a few seconds the valve goes to OF.

Disabling the Scheduler does not work to fix the issue. I do not see any way to log what is the issue.

The valve works ok through MQTT. Issues appear only when using BT controls.