TillFleisch / ESPHome-HLK-LD2450

ESPHome support for the HI-Link HLK-LD2450 millimeter wave sensor (external component) with support for custom zones using convex polygons.
MIT License
105 stars 19 forks source link

Problem with Polygon being not convex #8

Closed Aaroneisele55 closed 9 months ago

Aaroneisele55 commented 9 months ago

Hello, I have successfully set up your component, but I'm now struggling with the creation of zones, especially with the polygons not being convex. Is there a way to make this polygon convex with minimal changes to the coordinates? If yes, could you please let me know how to do it so I can create that zone? The values are based on testing (walking to where the zone points should later be and taking notes of the X and Y) and should not be varied much.

zones:
      - zone:
          name: "Tür aussen"
          margin: 10cm
          target_timeout: 0s
          polygon:
            - point: 
                x: 1.42m
                y: 3m
            - point:
                x: 0.66m
                y: 3m
            - point:
                x: 0.66m
                y: 3.2m
            - point: 
                x: 1.42m
                y: 3.2m

Best regards Aaron Eisele

TillFleisch commented 9 months ago

[...]especially with the polygons not being convex [...] Is there a way to make this polygon convex [...]

The provided polygon is already convex. The supplied code snipped (in a minimal example) compiled and ran without problems. Are you sure this is the zone causing problems? At which point do experience problems (config validation, compilation, log configuration output, zone not detecting)? Posting a complete (or a minimal non working) configuration will make troubleshooting this issue easier.

Keep in mind that the order of points making up a polygon is important. If you were to switch two points of one side of the polygon you'd end up with an 'hourglass' shape instead of a rectangle.

Aaroneisele55 commented 9 months ago

Hello, The issue just magically resolved itself after I changed the order of the points to this one:

polygon:
            - point: 
                x: 1.42m
                y: 3m
            - point:
                x: 0.66m
                y: 3m
            - point:
                x: 0.66m
                y: 3.2m
            - point: 
                x: 1.42m
                y: 3.2m

I don't know why, but it works now....

Best regards Aaron Eisele