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

Netatmo wind sensor probably not parsed correctly #15

Closed
2 tasks done
matteofranceschini opened this issue Aug 13, 2020 · 5 comments · Fixed by #16
Closed
2 tasks done

Netatmo wind sensor probably not parsed correctly #15

matteofranceschini opened this issue Aug 13, 2020 · 5 comments · Fixed by #16
Assignees
Labels
enhancement New feature or request

Comments

@matteofranceschini
Copy link
Contributor

matteofranceschini commented Aug 13, 2020

Checklist:

  • I updated to the latest version available
  • I cleared the cache of my browser

Release with the issue:
not relevant
Last working release (if known):

Browser and Operating System:
safari,chrome, homeassistant app, MacOs

Description of problem:

I have a Netatmo wind sensor, but the default HA integration provides the information with both text and degrees, for example like W (240°), as shown in picture.

I think that there's a problem for the compass-card to parse this kind of information as, I assume, it expects just one of the two information and not both.

As you can see, it does not crash or anything, but obviously the arrow does not point in the correct direction!

image

For reference, this is the code that generates this card:
cards:
  - detail: 2
    entity: sensor.netatmo_jori_palace_anemogio_gust_strength
    graph: line
    name: Raffiche
    type: sensor
  - direction_offset: 0
    entity: sensor.netatmo_jori_palace_anemogio_angle
    name: Vento
    type: 'custom:compass-card'
    secondary_entity: sensor.netatmo_jori_palace_anemogio_wind_strength
type: horizontal-stack

I'm not fluent in javascript nor python, but i think that the problem could just be that the code just checks if the value given is NaN and does not search for a number in the string, to be parsed.

Javascript errors shown in the web inspector (if applicable):


Additional information:
If needed, I can do some testing.

@matteofranceschini matteofranceschini added the bug Something isn't working label Aug 13, 2020
@tomvanswam tomvanswam added enhancement New feature or request and removed bug Something isn't working labels Aug 13, 2020
@tomvanswam
Copy link
Owner

You're correct, only degrees or abbreviation is possible at the moment (as stated in the README).

I can parse for the numbers and only use those, so I'll change this to an enhancement.

@tomvanswam tomvanswam self-assigned this Aug 13, 2020
tomvanswam added a commit that referenced this issue Aug 13, 2020
@matteofranceschini
Copy link
Contributor Author

Thank you! As a C programmer that triple equal sign gave me a heart attack, but it seems I‘ve just discovered one of the wonders of javascript :)

I’ll test your edit on monday, when I have a little time !

Ps: I love the design of your compass card, it’s a strange thing that we don’t have it natively in Homeassistant. Thank you for this magnificent work!

@tomvanswam tomvanswam linked a pull request Aug 14, 2020 that will close this issue
@tomvanswam
Copy link
Owner

tomvanswam commented Aug 14, 2020

I think I got it, a input_text entity helps a lot with testing this as you can set it to whatever you want.

One note though, currently all characters which are not numbers or dots are removed from the entity state. If the state is something like North 342 degrees @ 15kn it will be parsed to 342615 in which all multiples of 360 are removed so the resulting direction will become 255.

My RegEx-fu is not strong enough yet (or my google skills fail me) at only getting the first number sequence in the string and only use that.

Workaround in all not supported cases would be

  • create a template sensor
  • parse your entity in a correct way so you get 0-360 degrees into the value_template of said sensor
  • use the template sensor in the compass-card

@matteofranceschini
Copy link
Contributor Author

If you can use a regex, you could try with something like this:

\b\d?\d?\d\b

This should get you just the first time you find at least 1 number, maximum 3, and no other number, if any, afterwards.

I'm not a regex expert, but I've tried it and it seems to get the result we want :)

tomvanswam added a commit that referenced this issue Aug 15, 2020
Better direction detection in Netatmo sensor state (only use first group of numbers for direction)
@tomvanswam
Copy link
Owner

I updated the regex a bit, your propsal inspired me to have a second look.

First I replace all the whitespaces now, so any negative sign in front of the number would have a space removed if it was in between.
Second I fixed the negative directions (was not working for the parsed string).
And third I search for all consecutive numbers + a dot and max 1 decimal (also consecutive). Should be good enough I think.

Note, I'll put this in the next version (0.2.1, or 0.3.0, depending on the other changes in the next version)

@tomvanswam tomvanswam mentioned this issue Aug 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants