BottlecapDave / HomeAssistant-OctopusEnergy

Unofficial Home Assistant integration for interacting with Octopus Energy
https://bottlecapdave.github.io/HomeAssistant-OctopusEnergy/
MIT License
581 stars 60 forks source link

Device targets don't work #76

Closed cspiby closed 1 year ago

cspiby commented 1 year ago

I've set this up via HACS, the data appears to be there as I can see the prices under the attributes but the device targets don't have any data under them so they never trigger, this is what I see under HA states.

cspiby commented 1 year ago

Screenshot_20221022-100742_Chrome

BottlecapDave commented 1 year ago

Sorry to hear that no times are coming through as part of your target sensor. Do you have any errors in your Home Assistant logs? What tariff are you on?

cspiby commented 1 year ago

I can't see any errors in my logs related to your integration, maybe if I was able to turn on verbose logging for your integration it may shed some light? Is that possible?

This is my the cost data is presented, I'm on Octopus Agile

Screenshot_20221022-184617_Home Assistant

BottlecapDave commented 1 year ago

You can set your log levels as per the instructions at https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy#i-have-sensors-that-are-missing

BottlecapDave commented 1 year ago

Also does the history of the sensor ever say it came on? The time at which you posted the issue, it might have hit the small window where there wasn't enough time available within your specified target window and it hadn't started looking at the following days window.

cspiby commented 1 year ago

The sensor hasn't been 'on' since setting it up, I would have thought it would have found a 30 minute cheap period in the last day.

I'll enable debug and get back to you.

cspiby commented 1 year ago

this is all the logs show

2022-10-22 21:57:15.002 DEBUG (MainThread) [custom_components.octopus_energy] Finished fetching rates data in 0.000 seconds (success: True) 2022-10-22 21:57:15.003 INFO (MainThread) [custom_components.octopus_energy.binary_sensor] Updating OctopusEnergyTargetRate dishwasher 2022-10-22 21:57:15.005 INFO (MainThread) [custom_components.octopus_energy.binary_sensor] Updating OctopusEnergyTargetRate washing_machine 2022-10-22 21:57:15.007 INFO (MainThread) [custom_components.octopus_energy.binary_sensor] Updating OctopusEnergyTargetRate testing 2022-10-22 21:57:57.002 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Finished fetching rates data in 0.000 seconds (success: True) 2022-10-22 21:57:57.004 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Finished fetching rates data in 0.000 seconds (success: True) 2022-10-22 21:57:57.006 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Finished fetching rates data in 0.000 seconds (success: True) 2022-10-22 21:58:15.002 DEBUG (MainThread) [custom_components.octopus_energy] Finished fetching rates data in 0.000 seconds (success: True) 2022-10-22 21:58:15.003 INFO (MainThread) [custom_components.octopus_energy.binary_sensor] Updating OctopusEnergyTargetRate dishwasher 2022-10-22 21:58:15.005 INFO (MainThread) [custom_components.octopus_energy.binary_sensor] Updating OctopusEnergyTargetRate washing_machine 2022-10-22 21:58:15.008 INFO (MainThread) [custom_components.octopus_energy.binary_sensor] Updating OctopusEnergyTargetRate testing 2022-10-22 21:58:57.002 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Finished fetching rates data in 0.000 seconds (success: True) 2022-10-22 21:58:57.005 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Finished fetching rates data in 0.000 seconds (success: True) 2022-10-22 21:58:57.007 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Finished fetching rates data in 0.000 seconds (success: True) 2022-10-22 21:59:15.002 DEBUG (MainThread) [custom_components.octopus_energy] Finished fetching rates data in 0.000 seconds (success: True) 2022-10-22 21:59:15.004 INFO (MainThread) [custom_components.octopus_energy.binary_sensor] Updating OctopusEnergyTargetRate dishwasher 2022-10-22 21:59:15.005 INFO (MainThread) [custom_components.octopus_energy.binary_sensor] Updating OctopusEnergyTargetRate washing_machine 2022-10-22 21:59:15.008 INFO (MainThread) [custom_components.octopus_energy.binary_sensor] Updating OctopusEnergyTargetRate testing 2022-10-22 21:59:57.002 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Finished fetching rates data in 0.000 seconds (success: True) 2022-10-22 21:59:57.005 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Finished fetching rates data in 0.000 seconds (success: True) 2022-10-22 21:59:57.010 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Finished fetching rates data in 0.001 seconds (success: True)

cspiby commented 1 year ago

Hi, have you any more ideas, none of the created sensors are triggering and there has definitely been cheap periods over the last few days...

Screenshot 2022-10-26 160723

BottlecapDave commented 1 year ago

If I'm honest I'm not too sure why you're seeing this. All of the internal testing should have the sensor coming on. I have also created a new release (v4.6.3) with some additional logging to try and get some more insight. Am I correct in assuming you only have the one meter, and if not that the target rate has been assigned to the correct meter?

cspiby commented 1 year ago

I have an export meter too but I'm definately choosing the correct one (mpan), I'll update to the newest and hopefully it will shed some light on what's happening!

cspiby commented 1 year ago

The new version isn't actually creating the sensors now, I've removed the integration and re-added it from scratch but still the same, this is the error in the log

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 691, in _async_add_entity await entity.add_to_platform_finish() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 777, in add_to_platform_finish self.async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 533, in async_write_ha_state self._async_write_ha_state() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 571, in _async_write_ha_state state = self._stringify_state(available) File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 539, in _stringify_state if (state := self.state) is None: File "/usr/src/homeassistant/homeassistant/components/binary_sensor/__init__.py", line 211, in state if (is_on := self.is_on) is None: File "/config/custom_components/octopus_energy/binary_sensor.py", line 125, in is_on _LOGGER.debug(f'{len(all_rates)} rate periods found for meter {self._config[CONFIG_TARGET_MPAN]}') TypeError: object of type 'NoneType' has no len()

BottlecapDave commented 1 year ago

🤦 Sorry about that. I've released a new version which will hopefully fix this issue

cspiby commented 1 year ago

It's not producing errors in the log now but it's not producing much else either.

BottlecapDave commented 1 year ago

That is very odd. I've setup a target sensor similar to you with log level set to debug and the following is an example of the output I would expect (I'm on a fixed rate)

2022-10-29 14:35:39.951 DEBUG (MainThread) [custom_components.octopus_energy.binary_sensor] Updating OctopusEnergyTargetRate dishwasher
2022-10-29 14:35:39.951 DEBUG (MainThread) [custom_components.octopus_energy.binary_sensor] 0 rate periods found for meter XXX
2022-10-29 14:35:39.952 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Finding rates between 2022-10-29 13:35:39.951884+00:00 and 2022-10-29 21:00:00+00:00
2022-10-29 14:35:39.952 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] 0 applicable rates found
...
2022-10-29 14:35:45.856 DEBUG (MainThread) [custom_components.octopus_energy.binary_sensor] Updating OctopusEnergyTargetRate dishwasher
2022-10-29 14:35:45.856 DEBUG (MainThread) [custom_components.octopus_energy.binary_sensor] 98 rate periods found for meter XXX
2022-10-29 14:35:45.857 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Finding rates between 2022-10-29 13:35:45.856910+00:00 and 2022-10-29 21:00:00+00:00
2022-10-29 14:35:45.857 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] 14 applicable rates found
2022-10-29 14:35:45.857 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Total rates for current block 20.874. Total rates for best block 20.874
2022-10-29 14:35:45.857 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Total rates for current block 20.874. Total rates for best block 20.874
2022-10-29 14:35:45.857 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Total rates for current block 20.874. Total rates for best block 20.874
2022-10-29 14:35:45.857 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Total rates for current block 20.874. Total rates for best block 20.874
2022-10-29 14:35:45.857 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Total rates for current block 20.874. Total rates for best block 20.874
2022-10-29 14:35:45.857 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Total rates for current block 20.874. Total rates for best block 20.874
2022-10-29 14:35:45.858 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Total rates for current block 20.874. Total rates for best block 20.874
2022-10-29 14:35:45.858 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Total rates for current block 20.874. Total rates for best block 20.874
2022-10-29 14:35:45.858 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Total rates for current block 20.874. Total rates for best block 20.874
2022-10-29 14:35:45.858 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Total rates for current block 20.874. Total rates for best block 20.874
2022-10-29 14:35:45.858 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Total rates for current block 20.874. Total rates for best block 20.874
2022-10-29 14:35:45.858 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Total rates for current block 20.874. Total rates for best block 20.874
2022-10-29 14:35:45.858 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Total rates for current block 20.874. Total rates for best block 20.874
cspiby commented 1 year ago

For some reason the debug logger code was removed from my configuration.yaml

Will see what it produces now that is set correctly...

2022-10-30 17:09:30.030 DEBUG (MainThread) [custom_components.octopus_energy] Finished fetching rates data in 0.000 seconds (success: True)
2022-10-30 17:09:30.030 DEBUG (MainThread) [custom_components.octopus_energy.binary_sensor] Updating OctopusEnergyTargetRate washing_machine
2022-10-30 17:09:30.030 DEBUG (MainThread) [custom_components.octopus_energy.binary_sensor] None rate periods found for meter 1610005xxxxxxx
2022-10-30 17:09:30.030 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Finding rates between 2022-10-30 17:29:30.030725+00:00 and 2022-10-30 21:00:00+00:00
2022-10-30 17:09:30.030 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] 0 applicable rates found
2022-10-30 17:10:20.001 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Finished fetching rates data in 0.000 seconds (success: True)
2022-10-30 17:10:20.001 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Finished fetching rates data in 0.000 seconds (success: True)
2022-10-30 17:10:20.008 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Finished fetching rates data in 0.000 seconds (success: True)
2022-10-30 17:10:21.455 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Calculated previous gas consumption cost for '50345xxxxx/E6S1xxxxxxxx'...
2022-10-30 17:10:21.496 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Calculated previous electricity consumption cost for '1650000xxxxxxx/21E5xxxxxx'...
2022-10-30 17:10:21.526 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Calculated previous electricity consumption cost for '1610005xxxxxxx/21E5xxxxxx'...
2022-10-30 17:10:30.000 DEBUG (MainThread) [custom_components.octopus_energy] Finished fetching rates data in 0.000 seconds (success: True)
2022-10-30 17:10:30.000 DEBUG (MainThread) [custom_components.octopus_energy.binary_sensor] Updating OctopusEnergyTargetRate washing_machine
2022-10-30 17:10:30.000 DEBUG (MainThread) [custom_components.octopus_energy.binary_sensor] None rate periods found for meter 1610005xxxxxxx
2022-10-30 17:10:30.000 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Finding rates between 2022-10-30 17:30:30.000850+00:00 and 2022-10-30 21:00:00+00:00
2022-10-30 17:10:30.000 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] 0 applicable rates found
2022-10-30 17:11:20.001 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Finished fetching rates data in 0.000 seconds (success: True)
2022-10-30 17:11:20.004 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Finished fetching rates data in 0.000 seconds (success: True)
2022-10-30 17:11:20.004 DEBUG (MainThread) [custom_components.octopus_energy.sensor] Finished fetching rates data in 0.000 seconds (success: True)
2022-10-30 17:11:30.001 DEBUG (MainThread) [custom_components.octopus_energy] Finished fetching rates data in 0.000 seconds (success: True)
2022-10-30 17:11:30.001 DEBUG (MainThread) [custom_components.octopus_energy.binary_sensor] Updating OctopusEnergyTargetRate washing_machine
2022-10-30 17:11:30.001 DEBUG (MainThread) [custom_components.octopus_energy.binary_sensor] None rate periods found for meter 1610005xxxxxxx
2022-10-30 17:11:30.001 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Finding rates between 2022-10-30 17:31:30.001714+00:00 and 2022-10-30 21:00:00+00:00
cspiby commented 1 year ago

Still the same issue a day later, is there anything else I can do to help narrow down this issue?

2022-10-31 18:07:54.001 DEBUG (MainThread) [custom_components.octopus_energy.binary_sensor] Updating OctopusEnergyTargetRate washing_machine
2022-10-31 18:07:54.001 DEBUG (MainThread) [custom_components.octopus_energy.binary_sensor] None rate periods found for meter 161000xxxxxxx
2022-10-31 18:07:54.001 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] Finding rates between 2022-10-31 18:27:54.001751+00:00 and 2022-10-31 21:00:00+00:00
2022-10-31 18:07:54.001 DEBUG (MainThread) [custom_components.octopus_energy.target_sensor_utils] 0 applicable rates found
BottlecapDave commented 1 year ago

hmm odd that your rates are coming back as None. I'll try and dig and see why that might be.

BottlecapDave commented 1 year ago

I think I've found the issue. I've created a beta release at https://github.com/BottlecapDave/HomeAssistant-OctopusEnergy/releases/tag/v4.6.5-beta1, which would be great if you could give it a test

cspiby commented 1 year ago

That seems to have done the trick, nice work!