BottlecapDave / HomeAssistant-OctopusEnergy

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

Issue accessing attributes from electricity current rate #59

Closed Shaun-Harrison closed 1 year ago

Shaun-Harrison commented 1 year ago

I'm trying to access the attributes of the current rate for electricity - this is working fine for gas but not for electricity, i believe it's because they are all nested within the 'rate'

These entries in the template are as follows

value_template: "{{ state_attr('sensor.octopus_energy_gas_e6s23761231961_2761953705_current_rate', 'value_inc_vat') }}"

value_template: "{{ state_attr('sensor.octopus_energy_electricity_19l3865854_2199994503050_current_rate','rate') }}"

value_template: "{{ state_attr('sensor.octopus_energy_electricity_19l3865854_2199994503050_current_rate','value_inc_vat') }}"

Give the output of

value_template: "8.9355"

value_template: "{'value_exc_vat': 31.29, 'value_inc_vat': 32.8545, 'valid_from': datetime.datetime(2022, 8, 30, 15, 30, tzinfo=datetime.timezone.utc), 'valid_to': datetime.datetime(2022, 8, 30, 16, 0, tzinfo=datetime.timezone.utc), 'tariff_code': 'E-1R-LOYAL-FIX-12M-22-01-27-K'}"

value_template: "None"

Can you either remove the nested 'rate' attribute, or provide a way to do something like rate.value_inc_vat which I've tried and got no luck

BottlecapDave commented 1 year ago

I'll look at exposing the attributes in a consistent way in the future. In the meantime, you can access the data you want in the following way

value_template: "{{ state_attr('sensor.octopus_energy_electricity_19l3865854_2199994503050_current_rate','rate')['value_inc_vat'] }}"
Shaun-Harrison commented 1 year ago

Perfect, thanks for this!