Skip to content

fix: handle None attribute values to prevent ValueError#60

Open
pilotak wants to merge 1 commit intomasterfrom
fix/issue-46-none-attribute-valueerror
Open

fix: handle None attribute values to prevent ValueError#60
pilotak wants to merge 1 commit intomasterfrom
fix/issue-46-none-attribute-valueerror

Conversation

@pilotak
Copy link
Copy Markdown
Owner

@pilotak pilotak commented Apr 8, 2026

Summary

  • Fixes ValueError: Template error: float got invalid input 'None' when an entity attribute returns None
  • Adds state_attr() is not none check to all template variants (time-based and value-based)
  • When the attribute is None, the sensor now gracefully falls back to unknown instead of crashing

Closes #46

Test plan

  • Configure a sensor with round_to pointing to an entity whose attribute can be None
  • Verify the sensor shows unknown instead of throwing a ValueError
  • Verify normal operation is unaffected when the attribute has a valid value

🤖 Generated with Claude Code

Add a `state_attr() is not none` check to templates so that when an
entity attribute returns None, the sensor falls back to 'unknown'
instead of raising a ValueError from the float/int Jinja2 filters.

Closes #46

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pilotak
Copy link
Copy Markdown
Owner Author

pilotak commented Apr 8, 2026

sorry it took that long @r-jean-pierre if you still have this issue can you try this fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A specific case creates ValueError

1 participant