Incorrect Power Based on Attributes with Fixed Strategy
Not sure if this is an issue or just user error but I have the below configuration to calculate the power of my furnace.
- entity_id: climate.main_thermostat
name: Furnace
unique_id: 5b072b6f-69b8-44ff-86b7-6670e87dd133
fixed:
power: >
{% if state_attr('climate.main_thermostat', 'fan_mode') == 'Low' %}
97.6
{% else %}
7.8
{% endif %}
states_power:
hvac_action|heating: 461.7
hvac_action|cooling: 439.7
I tested this when I set it up and it seemed to be working fine. I tested the template sensor with developer tools and it seems to be evaluating correctly so not sure what I'm missing. The power sensor just shows 0 when it should be 97.6. Any issues you see or suggestions I could try?
You cannot mix both power and states_power, you should use one of them not both.
Pretty sure states_power is prioritized.
So whenever there is another hvac_action selected than heating or cooling it will be 0, which matches the behaviour you are experiencing.
I suggest to also put the hvac attribute conditions in the template code, when you want to mix different conditions/attributes.
You could also have a look at composite which allows you to combine different strategies and conditions in one. But that would probably be overkill for your use case.
yeah I can try just use power with everything inside the template with if statement. It just get's more complex. I thought states_power was prioritized but then power was the fallback if it didn't match.
Your example code below shows using both so that's what this was based off of. The logic was that if hvac_action wasn't heating or cooling ie then it would be idle and fall back to the power which would be evaluated based on the fan_mode attribute
powercalc:
sensors:
- entity_id: media_player.sonos_living
fixed:
power: 12
states_power:
media_content_id|Spotify: 5
media_content_id|Youtube: 10
Tried doing this with just power. Template seems to evaluate correct and and syntax seems ok but for whatever reason it's not generating a power and energy sensor after I reboot. The entity that it used to use it just dead. tried changing the name to furnace2 but still doesn't create anything
- entity_id: climate.main_thermostat
name: Furnace2
unique_id: 5b072b6f-69b8-44ff-86b7-6670e87dd132
fixed:
power: >
{% if state_attr('climate.main_thermostat', 'hvac_action') == 'heating' %}
461.7
{% elif state_attr('climate.main_thermostat', 'hvac_action') == 'cooling' %}
439.7
{% elif state_attr('climate.main_thermostat', 'hvac_action') == 'idle' and state_attr('climate.main_thermostat', 'fan_mode') == 'Low' %}
97.6
{% elif state_attr('climate.main_thermostat', 'hvac_action') == 'idle' and state_attr('climate.main_thermostat', 'fan_mode') == 'Auto low' %}
7.8
{% else %}
0
{% endif %}
yeah I can try just use power with everything inside the template with if statement. It just get's more complex. I thought
states_powerwas prioritized but thenpowerwas the fallback if it didn't match.Your example code below shows using both so that's what this was based off of. The logic was that if
hvac_actionwasn'theatingorcoolingie then it would beidleand fall back to thepowerwhich would be evaluated based on thefan_modeattribute
I see, my comments about mixed not being support was not right. power is indeed used as fallback when no states_power matches.
Not sure yet why template evalutation is not working in this scenario. I will be able to have a look into it and add some tests for it within a few days.
Tried doing this with just
power. Template seems to evaluate correct and and syntax seems ok but for whatever reason it's not generating a power and energy sensor after I reboot. The entity that it used to use it just dead. tried changing the name tofurnace2but still doesn't create anything
Did you check the logs for any errors? There should probably be some.
Sorry for my ignorance, where do I find the logs? I didn't see anything under System, Logs. Is there another place?
And thanks for testing out the template for combining the two
Did you check the logs for any errors? There should probably be some.
Found something that showed up in logs
This error originated from a custom integration.
Logger: custom_components.powercalc.sensors.power
Source: custom_components/powercalc/sensors/power.py:208
integration: Powercalc (documentation, issues)
First occurred: June 4, 2025 at 12:18:52 AM (1 occurrence)
Last logged: June 4, 2025 at 12:18:52 AM
climate.main_thermostat: Skipping sensor setup: This entity can only work with 'states_power' not 'power'
This could possibly explain why the original method was messing up as well because if it's not allowing for power so whenever that was the fallback it choked and went to zero
Looking into this further now.
The power sensor just shows 0 when it should be 97.6
Could you share the state and state attributes of the climate entity when this is the case from Developer Tools?
I have made a quick unit tests, and following was working for me with same yaml configuration as you shared. Assuming:
- state: fan
- state_attributes: hvac_action: fan, fan_mode: low
Returns: 97.60
This entity can only work with 'states_power' not 'power'
This is a validation I put into place once to prevent usage of power for non binary entities (on/off). However on hindsight it makes sense to support climate entities as well, because when I look into my own climate entities they are set to off when they are turned off, and the state is set to the hvac action (cooling, heating etc) for me when turned on.
So it makes sense to just support it as well, use standby_power when off, and return power value of evaluate template when any other state than off.
The power sensor just shows 0 when it should be 97.6
Could you share the state and state attributes of the climate entity when this is the case from Developer Tools?
Yeah I'll share it when it does it again. And I'll also keep an eye on the logs. I put back my original yaml configuration and it's working now. It worked initially as well so not sure what went wrong.
Ok let me know if you can reproduce and the state at that moment. Thanks!
Closing this issue for now, please let me know it you can reproduce, than we'll reopen
Closing this issue for now, please let me know it you can reproduce, than we'll reopen
Issue came back! So weird! It's currently showing zero
Here is the current states of the thermostat and a history of the power. I checked the logs but didn't see anything. Is there a way to isolate logs just for Powercalc?
Seems to be off and on for whatever reason. It was all zero for two days and then started working again. There was then a short period of zero and then worked...weird!
In your screenshot of the attributes I see climate.main_thermostat is off.
That would be the reason when off it won't record any power and look at standby_power property. When this is empty it will go to 0.
In your screenshot of the attributes I see
climate.main_thermostatisoff. That would be the reason whenoffit won't record any power and look atstandby_powerproperty. When this is empty it will go to0.
Oh good call! I just confirmed that it does go to zero when it’s set to off. Can you help me understand that a little better? So the default mode is if it’s set to off it will fall back to standby_power even though the yaml is only looking at attributes?
Any configured strategy for powercalc will only be called/calculated when the entity has another state than off.
For off always the configured standby_power will be considered.
I consider it an issue than your climate entity is off but the fan is still running. off really means the device is off and HA integration should behave that way.
https://www.home-assistant.io/integrations/climate/
Fan only seems to be the right state in your scenario. So I would definitely recommend reporting this issue on HA core of custom integration creator when you are using custom integration to integrate your furnace.
standby_power also supports templates, so you can also define template there to solve.
Ahh, yeah I get what you're saying. Yeah i'll definitely try and report that. Was easy enough to fix with standby_power though. Thanks for all your help!