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

Æ/Ø/Å breaks sensors #12

Closed
allanpersson opened this issue Apr 29, 2020 · 18 comments · Fixed by #14
Closed

Æ/Ø/Å breaks sensors #12

allanpersson opened this issue Apr 29, 2020 · 18 comments · Fixed by #14

Comments

@allanpersson
Copy link

allanpersson commented Apr 29, 2020

Thanks for a awesome script.

When using Danish unique letters (Æ, Ø & Å) the sensor breaks. I'm not sure if there exists a official way to handle that issue regarding writing codes, but Home Assistant transform them to:
æ: ae
ø: o
å: aa

Config

---
# https://github.com/mf-social/ps-date-countdown
alias: "[System] Date Countdown"
trigger:
  - platform: time
    at: '00:00:01'
  - platform: homeassistant
    event: start
action:
  - service: python_script.date_countdown
    data:
      name: Juleaften
      type: anniversary
      date: 24/12/1981
      icon: "mdi:pine-tree"
  - service: python_script.date_countdown
    data:
      name: 'Nytårsaften'
      type: anniversary
      date: 31/12/1981
      icon: "mdi:pine-tree"

Log

Log Details (ERROR)
Logger: homeassistant.components.python_script.date_countdown.py
Source: core.py:736
Integration: Python Scripts (documentation, issues)
First occurred: 4:01:51 PM (1 occurrences)
Last logged: 4:01:51 PM

Error executing script: Invalid entity id encountered: sensor.anniversary_nytårsaften. Format should be <domain>.<object_id>
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/python_script/__init__.py", line 205, in execute
    exec(compiled.code, restricted_globals)
  File "date_countdown.py", line 50, in <module>
  File "/usr/src/homeassistant/homeassistant/core.py", line 954, in set
    context,
  File "/usr/local/lib/python3.7/concurrent/futures/_base.py", line 435, in result
    return self.__get_result()
  File "/usr/local/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
    raise self._exception
  File "/usr/src/homeassistant/homeassistant/util/async_.py", line 53, in run_callback
    future.set_result(callback(*args))
  File "/usr/src/homeassistant/homeassistant/core.py", line 994, in async_set
    state = State(entity_id, new_state, attributes, last_changed, None, context)
  File "/usr/src/homeassistant/homeassistant/core.py", line 736, in __init__
    f"Invalid entity id encountered: {entity_id}. "
homeassistant.exceptions.InvalidEntityFormatError: Invalid entity id encountered: sensor.anniversary_nytårsaften. Format should be <domain>.<object_id>

I'm aware of the use of friendly_name, but many names in Denmark fx have special letters.

@point-4ward
Copy link
Owner

Noted - I'll have a look when I get a sec.

Thanks for the report 🙂

@allanpersson
Copy link
Author

@mf-social thank you so much 🙏

P. S. A third type of date countdown for onetime events with a negative counter when passed would be awesome. This could be a time since:

  • I met my best friend.
  • I was in Africa.
    Etc etc etc

@point-4ward
Copy link
Owner

Can you outline how your third sensor type would look/behave please?

If it's viable I'll try and add it at the same time as fixing the Scandinavian letters (between work and home schooling I'm mega short on time at the moment, but I'll definitely get to it soon, promise 🙂 )

@allanpersson
Copy link
Author

Yes of course... Something like:

---
# https://github.com/mf-social/ps-date-countdown
alias: "[System] Date Countdown"
trigger:
  - platform: time
    at: '00:00:01'
  - platform: homeassistant
    event: start
action:
  - service: python_script.date_countdown
    data:
      name: First time in Africa
      type: meaningfulkeyword
      date: 01/01/2020
      icon: "mdi:lion"

Instead of count to next it should be last (https://www.timeanddate.com/date/durationresult.html?d1=1&m1=1&y1=2020&d2=30&m2=4&y2=2020).

sensor.meaningfulkeyword_first_time_in_africa
friendly_name: First time in Africa
state: However many days since 1th Januar 2020
Weeks/Years: However many weeks(and years) since 1th Januar 2020

@point-4ward
Copy link
Owner

So in that example, if today was the first of February 2021 it would show 1 year and 31 days SINCE the date?

@allanpersson
Copy link
Author

Exactly, it will be a "lookback" counter where you mark special days.

  • Time since stop smoking
  • time since cancer free
    Etc

Where you don't necessarily celebrate a anniversary, but want to know how many days/years

@point-4ward
Copy link
Owner

Yeah, with you now 🙂

I'll add that too, no worries 👍

I'll sort both when I get a chance 🙂

@point-4ward
Copy link
Owner

Hi @allanpersson,

Sorry for the delay here - can you try the code I have put in the 'scandanavia' branch please and make sure it works for you regarding the extra charcaters?

Please check against capital and lowercase versions and make sure it looks OK 🙂

I'll get on with the count-up suggestion shortly 👍

@allanpersson
Copy link
Author

Awesome 👌
I'll check it right away, will let you know within the next half hour 🙏

@allanpersson
Copy link
Author

@mf-social i just did a couple of tests with and without friendly_name and it works like a charm in both cases (Y) Good job m8

@point-4ward
Copy link
Owner

Ace 😎 - keep that as your running version then, I'll get your other suggestion working, update the docs and then do an official release to hacs when it's all done 👍

@point-4ward
Copy link
Owner

Hey again @allanpersson 😎

Would you do me a favour and check that my 'count_up' branch is working for you please?

Just add reverse: True to any sensor that you want to count up instead of down and let me know?

If it's working properly I'll release it on HACS next time I'm sat at a computer 👍

@allanpersson
Copy link
Author

@mf-social i'm about to test it, will be right back with comment 🙏

@point-4ward
Copy link
Owner

Ha, no hurry, I'm at work until 3am (it's currently 6pm here), then sleep, then general house stuff before I can do anything more with this - so take your time 😎

@allanpersson
Copy link
Author

I have just tested the changed version and here is my comments:

  • The reverse option is genius 👏👏👏 Much better than a third type.
  • I haven't tested if both works but else "True" should be with lower case.

Thank you for your effort 🙏

@point-4ward
Copy link
Owner

Confirm it appears to be working correctly as far as you can tell?

@allanpersson
Copy link
Author

It works like a charm and also the count is correct 👍

@point-4ward
Copy link
Owner

Excellent - I will wrap it all up in to a release and get it out to hacs tomorrow 😃

Thanks for both the bug report and the suggestion 👍

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 a pull request may close this issue.

2 participants