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

AttributeError: 'NoneType' object has no attribute 'state' #69

Closed
upais opened this issue Dec 4, 2021 · 17 comments · Fixed by #89
Closed

AttributeError: 'NoneType' object has no attribute 'state' #69

upais opened this issue Dec 4, 2021 · 17 comments · Fixed by #89
Labels
help wanted Extra attention is needed under investigation If its not clear whats the problem

Comments

@upais
Copy link

upais commented Dec 4, 2021

Continued - #43
Two TVRs work, two don't.
There is an error when starting HA:

2021-12-05 15:25:30 DEBUG (MainThread) [custom_components.ai_thermostat.climate] Undefined target temperature, falling back to 5.0
2021-12-05 15:25:40 INFO (MainThread) [custom_components.ai_thermostat.climate] Starting ai_thermostat for ai_bedroom with version: 0.7.8 waiting for entity to be ready...
2021-12-05 15:25:45 INFO (MainThread) [custom_components.ai_thermostat.climate] ai_thermostat ai_bedroom still waiting for sensor.temperature_humidity_hall_temperature to be available
2021-12-05 15:25:45 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/ai_thermostat/climate.py", line 309, in startUp
if trv_state or trv_state.state in (
AttributeError: 'NoneType' object has no attribute 'state'
====== Restart AI THERMOSTAT ======
2021-12-05 15:26:54 INFO (MainThread) [custom_components.ai_thermostat.climate] Starting ai_thermostat for ai_bedroom with version: 0.7.8 waiting for entity to be ready...
2021-12-05 15:26:54 DEBUG (MainThread) [custom_components.ai_thermostat.climate] Undefined target temperature, falling back to 5.0
2021-12-05 15:26:59 INFO (MainThread) [custom_components.ai_thermostat.climate] ai_thermostat ai_bedroom still waiting for sensor.temperature_humidity_hall_temperature to be available
2021-12-05 15:26:59 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/ai_thermostat/climate.py", line 309, in startUp
if trv_state or trv_state.state in (
AttributeError: 'NoneType' object has no attribute 'state'

It doesn't work:

hvac_modes:
  - auto
  - 'off'
  - cool
  - heat
  - dry
  - fan_only
min_temp: 5
max_temp: 35
target_temp_step: 0.5
preset_modes:
  - none
  - programming
  - manual
  - temporary_manual
  - holiday
current_temperature: 27
temperature: 22
preset_mode: manual
battery: 75
boost_heating: 'OFF'
boost_heating_countdown: 0
boost_heating_countdown_time_set: 100
child_lock: LOCK
current_heating_setpoint: 22
device:
  applicationVersion: 64
  dateCode: ''
  friendlyName: trv_bedroom
  hardwareVersion: 1
  ieeeAddr: '0x84fd27fffe8c3d13'
  manufacturerID: 4098
  manufacturerName: _TZE200_b6wax7g0
  model: BRT-100-TRV
  networkAddress: 35585
  powerSource: Battery
  stackVersion: 0
  type: EndDevice
  zclVersion: 3
eco_mode: 'OFF'
eco_temperature: 18
last_seen: '2021-12-05T14:23:23.281Z'
linkquality: 66
local_temperature: 27
local_temperature_calibration: 0
max_temperature: 35
min_temperature: 5
position: 0
preset: manual
program_saturday:
  saturday: '6h:0m 24°C,  12h:0m 23°C,   14h:30m 22°C,  17h:30m 21°C '
program_sunday:
  sunday: '  6h:0m 19°C,  12h:30m 20°C,  14h:30m 21°C,  18h:30m 20°C '
program_weekday:
  weekday: ' 6h:0m 20°C,  11h:30m 21°C,  13h:30m 22°C,  17h:30m 23°C '
programming_mode: >-
  06:00/20°C  11:30/21°C  13:30/22°C  17:30/23°C  06:00/24°C  12:00/23°C 
  14:30/22°C  17:30/21°C  06:00/19°C  12:30/20°C  14:30/21°C  18:30/20°C
update:
  state: idle
update_available: false
window: CLOSED
window_detection: 'OFF'
friendly_name: trv_bedroom
supported_features: 17
  - platform: ai_thermostat
    name: ai_bedroom
    thermostat: climate.tvr_bedroom
    temperature_sensor: sensor.temperature_humidity_hall_temperature

It works:

hvac_modes:
  - auto
  - 'off'
  - cool
  - heat
  - dry
  - fan_only
min_temp: 5
max_temp: 35
target_temp_step: 0.5
preset_modes:
  - none
  - programming
  - manual
  - temporary_manual
  - holiday
current_temperature: 38
temperature: 35
preset_mode: manual
battery: 86
boost_heating: 'OFF'
boost_heating_countdown: 0
boost_heating_countdown_time_set: 100
child_lock: LOCK
current_heating_setpoint: 35
device:
  applicationVersion: 64
  dateCode: ''
  friendlyName: trv_children
  hardwareVersion: 1
  ieeeAddr: '0x84fd27fffea664aa'
  manufacturerID: 4098
  manufacturerName: _TZE200_b6wax7g0
  model: BRT-100-TRV
  networkAddress: 56984
  powerSource: Battery
  stackVersion: 0
  type: EndDevice
  zclVersion: 3
eco_mode: 'OFF'
eco_temperature: 18
last_seen: '2021-12-05T14:16:00.082Z'
linkquality: 105
local_temperature: 38
local_temperature_calibration: 0
max_temperature: 35
min_temperature: 5
position: 0
preset: manual
program_saturday:
  saturday: '6h:0m 24°C,  12h:0m 23°C,   14h:30m 22°C,  17h:30m 21°C '
program_sunday:
  sunday: '  6h:0m 19°C,  12h:30m 20°C,  14h:30m 21°C,  18h:30m 20°C '
program_weekday:
  weekday: ' 6h:0m 20°C,  11h:30m 21°C,  13h:30m 22°C,  17h:30m 23°C '
programming_mode: >-
  06:00/20°C  11:30/21°C  13:30/22°C  17:30/23°C  06:00/24°C  12:00/23°C 
  14:30/22°C  17:30/21°C  06:00/19°C  12:30/20°C  14:30/21°C  18:30/20°C
update:
  state: idle
update_available: false
window: CLOSED
window_detection: 'OFF'
friendly_name: trv_children
supported_features: 17
  - platform: ai_thermostat
    name: ai_children
    thermostat: climate.trv_children
    temperature_sensor: sensor.temperature_humidity_hall_temperature

Additional Information

  1. Reset TRV
  2. Pairing again with z2m
  3. Reinstalled the integration

Versions

TRV Model: BRT-100-TRV
Z2M Version: 1.22.1-1
HA Version: 2021.11.5
ai_thermostat version: 0.7.8

@KartoffelToby KartoffelToby added under investigation If its not clear whats the problem help wanted Extra attention is needed labels Dec 5, 2021
@KartoffelToby
Copy link
Owner

@IvanUpa Ok, i want to fix this issue finally.

but i need your Help because i cant reproduce your issue with my Devices.

have you enabled legacy mode in z2m and every of your device?

did you notice any different Output in HA in the working and not working devices?

is any child lock or window detection enabled in Z2M?

the other configs are the Same? same Sensor etc?

@upais
Copy link
Author

upais commented Dec 5, 2021

@KartoffelToby

// have you enabled legacy mode in z2m and on each of your devices?
Settings->Advanced->Legacy API? Yes, it's enabled.

// Have you noticed any differences in HA output on working and non-working devices?
Looked all I could, couldn't find any differences. I do not understand why they behave like this, and before version 0.7.2. they worked.

// Is child lock or window detection enabled in Z2M?
window detection=false, child lock=true (set it to false, no effect)

// Are the other configurations the same? the same sensor, etc.?
I noticed a difference in program_saturday, programming_mode, etc. between the working TVR and the problem TVR. I don't know why it is so after updating to 1.22.1-1. I took the configuration of another problem TVR and updated the ticket. I don't see any difference between them. Chinese magic...

@upais
Copy link
Author

upais commented Dec 6, 2021

Tried the solution from #73
The error remains, state=unavailable

@KartoffelToby
Copy link
Owner

As others reported, it shoud be fixed by 0.7.9

@upais
Copy link
Author

upais commented Dec 7, 2021

@KartoffelToby

I tried it yesterday. In 0.7.9 it breaks what worked.
Rolled back to 0.7.8 and did not report, because the change log did not indicate that the problem is fixed.

2021-12-07 18:49:37 DEBUG (MainThread) [custom_components.ai_thermostat.climate] Undefined target temperature, falling back to 5.0
2021-12-07 18:49:40 INFO (MainThread) [custom_components.ai_thermostat.climate] Starting ai_thermostat for ai_bedroom with version: 0.7.9 waiting for entity to be ready...
2021-12-07 18:49:40 INFO (MainThread) [custom_components.ai_thermostat.climate] Starting ai_thermostat for ai_children with version: 0.7.9 waiting for entity to be ready...
2021-12-07 18:49:45 INFO (MainThread) [custom_components.ai_thermostat.climate] ai_thermostat ai_bedroom still waiting for sensor.temperature_humidity_hall_temperature to be available
2021-12-07 18:49:45 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/ai_thermostat/climate.py", line 323, in startUp
if trv_state or trv_state.state in (
AttributeError: 'NoneType' object has no attribute 'state'
2021-12-07 18:49:45 INFO (MainThread) [custom_components.ai_thermostat.climate] ai_thermostat ai_children still waiting for climate.trv_children to be available
2021-12-07 18:49:45 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-07 18:49:45 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/ai_thermostat/climate.py", line 310, in startUp
mqtt_settemp = {"current_heating_setpoint": float(self.hass.states.get(self.heater_entity_id).attributes.get('current_heating_setpoint'))}
TypeError: float() argument must be a string or a number, not 'NoneType'

0.8.0:

2021-12-07 19:01:06 DEBUG (MainThread) [custom_components.ai_thermostat.climate] Undefined target temperature, falling back to 5.0
2021-12-07 19:01:06 DEBUG (MainThread) [custom_components.ai_thermostat.climate] Undefined target temperature, falling back to 5.0
2021-12-07 19:01:09 INFO (MainThread) [custom_components.ai_thermostat.climate] Starting ai_thermostat for ai_bedroom with version: 0.8.0 waiting for entity to be ready...
2021-12-07 19:01:09 INFO (MainThread) [custom_components.ai_thermostat.climate] Starting ai_thermostat for ai_children with version: 0.8.0 waiting for entity to be ready...
2021-12-07 19:01:14 INFO (MainThread) [custom_components.ai_thermostat.climate] ai_thermostat ai_bedroom still waiting for sensor.temperature_humidity_hall_temperature to be available
2021-12-07 19:01:14 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/ai_thermostat/climate.py", line 325, in startUp
if trv_state or trv_state.state in (
AttributeError: 'NoneType' object has no attribute 'state'
2021-12-07 19:01:14 INFO (MainThread) [custom_components.ai_thermostat.climate] ai_thermostat ai_children still waiting for climate.trv_children to be available
2021-12-07 19:01:14 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-07 19:01:14 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/ai_thermostat/climate.py", line 312, in startUp
mqtt_settemp = {"current_heating_setpoint": float(self.hass.states.get(self.heater_entity_id).attributes.get('current_heating_setpoint'))}
TypeError: float() argument must be a string or a number, not 'NoneType'

@KartoffelToby KartoffelToby reopened this Dec 7, 2021
@KartoffelToby
Copy link
Owner

@IvanUpa You wrote it breaks whats worked, are you mean it was working on 0.7.8?

@upais
Copy link
Author

upais commented Dec 8, 2021

@KartoffelToby

Yes. I attached the configs climate.tvr_bedroom and climate.trv_children. I specifically test only on these entities.
trv_children - in 0.7.8 works, but in 0.7.9 and 0.8.0 - does not work (state=unavailable), errors above. If after HA start make ai_thermostat restart, the error disappears and TRV works, but this is not normal behavior.
tvr_bedroom - doesn't work (state=unavailable) since 0.7.1 or 0.7.2 (I don't remember anymore).

@Cycor
Copy link
Contributor

Cycor commented Dec 8, 2021

The line 325 error I solved a while back in my local build, I made it
if trv_state and trv_state.state in (
instead of
if trv_state or trv_state.state in (

The error on 312 is up to @KartoffelToby to decide, I can't really see why the current_heating_setpoint is send to the same device at startup, but it should at least have a check if the device has that value available.

@KartoffelToby
Copy link
Owner

@Cycor i used "or" in this section to check if its not ready, anyway it was a thinking mistake i also believe it has to do with the no window sensor checking.

@IvanUpa

Can you checkout the current master?

Screenshot 2021-12-08 201536

@upais
Copy link
Author

upais commented Dec 8, 2021

@KartoffelToby

Everything is the same as it was on 0.7.8:
trv_children - works
trv_hall - does not work
Error:

2021-12-08 22:54:17 DEBUG (MainThread) [custom_components.ai_thermostat.climate] Undefined target temperature, falling back to 5.0
2021-12-08 22:54:27 INFO (MainThread) [custom_components.ai_thermostat.climate] Starting ai_thermostat for ai_hall with version: 0.7.8 waiting for entity to be ready...
2021-12-08 22:54:32 INFO (MainThread) [custom_components.ai_thermostat.climate] ai_thermostat ai_hall still waiting for sensor.temperature_humidity_hall_temperature to be available
2021-12-08 22:54:32 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/ai_thermostat/climate.py", line 309, in startUp
if trv_state or trv_state.state in (
AttributeError: 'NoneType' object has no attribute 'state'

@KartoffelToby
Copy link
Owner

@IvanUpa as i said, pls checkout the master: its 0.8.1 beta

@upais
Copy link
Author

upais commented Dec 9, 2021

@KartoffelToby

I understand and did as in the screenshot, but yesterday there was 0.7.8.
Now on 0.8.1 trv_children - works.
And for trv_hall:

2021-12-09 10:36:52 DEBUG (MainThread) [custom_components.ai_thermostat.climate] Undefined target temperature, falling back to 5.0
2021-12-09 10:37:02 INFO (MainThread) [custom_components.ai_thermostat.climate] Starting ai_thermostat for ai_hall with version: 0.8.1 waiting for entity to be ready...
2021-12-09 10:37:07 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:37:22 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:37:37 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:37:52 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:38:07 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:38:22 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:38:37 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:38:52 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:39:07 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:39:22 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:39:37 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:39:52 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:40:07 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:40:22 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:40:37 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:40:52 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:41:07 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:41:22 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:41:37 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:41:52 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:42:07 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:42:22 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:42:37 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:42:52 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:43:07 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:43:22 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:43:37 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:43:52 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:44:07 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:44:22 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:44:37 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:44:52 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:45:07 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:45:22 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:45:37 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...
2021-12-09 10:45:52 INFO (MainThread) [custom_components.ai_thermostat.climate] retry in 15s...

@KartoffelToby KartoffelToby linked a pull request Dec 10, 2021 that will close this issue
@KartoffelToby
Copy link
Owner

@IvanUpa OK looks like a found the right point, can you reinstall the master, and try it again? Didn't want to push a new version if its not fixed.

@upais
Copy link
Author

upais commented Dec 10, 2021

@KartoffelToby

trv_children - it works.
trv_hall:

2021-12-10 23:01:37 DEBUG (MainThread) [custom_components.ai_thermostat.climate] Undefined target temperature, falling back to 5.0
2021-12-10 23:01:47 INFO (MainThread) [custom_components.ai_thermostat.climate] Starting ai_thermostat for ai_hall with version: 0.8.1 waiting for entity to be ready...
2021-12-10 23:01:52 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/ai_thermostat/climate.py", line 329, in startUp
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 486, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 521, in _async_write_ha_state
attr.update(self.state_attributes or {})
File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 298, in state_attributes
if self.hvac_action:
File "/config/custom_components/ai_thermostat/climate.py", line 409, in hvac_action
if self.hass.states.get(self.heater_entity_id).attributes.get('position') is not None:
AttributeError: 'NoneType' object has no attribute 'attributes'

@upais
Copy link
Author

upais commented Dec 12, 2021

@KartoffelToby

It doesn't work :)

2021-12-12 11:02:58 INFO (MainThread) [custom_components.ai_thermostat.climate] Starting ai_thermostat for ai_hall with version: 0.8.1 waiting for entity to be ready...
2021-12-12 11:03:03 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/config/custom_components/ai_thermostat/climate.py", line 337, in startUp
self.async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 505, in async_write_ha_state
self._async_write_ha_state()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 540, in _async_write_ha_state
attr.update(self.state_attributes or {})
File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 298, in state_attributes
if self.hvac_action:
File "/config/custom_components/ai_thermostat/climate.py", line 435, in hvac_action
if self.hass.states.get(self.heater_entity_id).attributes.get('position') is not None:
AttributeError: 'NoneType' object has no attribute 'attributes'

There's something with TRV. What else can I do with it?

@Cycor
Copy link
Contributor

Cycor commented Dec 12, 2021

@IvanUpa Can you post the configuration for trv_hall and ai_hall?

@upais
Copy link
Author

upais commented Dec 12, 2021

@Cycor
@KartoffelToby

The configurations are the same as above, just this time I copied the log from trv_hall, not from trv_bedroom.

But the problem is solved. I was almost sure that the problem was these two TRVs and tried all sorts of things, even replaced the Zigbee stack with another one with different firmware. But then I did the following:

  1. Reset TRV
  2. Removed TRV from z2m
  3. Added TRV to z2m (and didn't change its name. This is IMPORTANT!)
  4. Restarted z2m (just the module, restarting HA does not work)
  5. Renamed TRV to trv_bedroom.
  6. Added configuration for ai_bebroom

Not sure why this worked on both TRVs, since essentially nothing changes.

Thank you for all the fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed under investigation If its not clear whats the problem
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants