Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Off Topic
    4. Microcontroller
    5. Tasmota ESPHome Presence Sensor LD2410

    NEWS

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Tasmota ESPHome Presence Sensor LD2410

    This topic has been deleted. Only users with topic management privileges can see it.
    • liv-in-sky
      liv-in-sky @Ralla66 last edited by liv-in-sky

      @ralla66

      ahh - dieser A0 ist ein brauchbarer wert - was für eine schwere geburt - vielen dank (heißt nicht, dass nicht noch mehr fragen kommen könnten 🙂 )

      Ralla66 1 Reply Last reply Reply Quote 0
      • Ralla66
        Ralla66 Most Active @liv-in-sky last edited by Ralla66

        @liv-in-sky

        prima soweit,
        an Out des Sensors wird ja nur bei keine Bewegung erkannt kein Pegel ausgegeben
        also 0 Volt.
        Bei Bewegung erkannt gibt dieser Out Pin 3,3 oder 5 Volt aus.

        Dann sollte das auch mit einem Button in Generic 18 gehen ( außer GPIO 0 und 2 ).
        Der Taster im Schema ist ja dein Out.
        Button beschaltung
        Somit würdest du dann im Sonoff Adapter per Mqtt ein true oder false im Datenpunkt bekommen.

        ADC gibt dir Werte aus, wobei 0 = 0 Volt sind und 1024 halt 3,3 Volt.
        A0 genannt in der Tasmota Generic Config und einzelner besonderer Pin an einer
        NodMCU.

        1 Reply Last reply Reply Quote 0
        • liv-in-sky
          liv-in-sky last edited by

          hat schon jmd mit esphome getestet und evtl ein fertiges yaml ? ich bekomm da nicht wirklich was zum laufen

          bei tasmota ist z.b das problem, daß ich -obwohl "serialsend 0" eingegeben wird, ich die app aufrufen muss, mich mit dem sensor verbinden muss (ich habe die bluetooth version), damit er dann auch in tasmota zu arbeiten beginnt.

          ps. falls sich jmd den sensor bestellt, braucht man die bluetooth version, um über die app den sensor einstellen zu können - nimmt man nur den sensor - also ohne"B" braucht man auch ein entwicklerboard, um die einstellungen testen zu können - bei tasmota - ob esphome letztlich über mqtt einstellungen zuläßt, weiß ich nicht

          BananaJoe 1 Reply Last reply Reply Quote 0
          • BananaJoe
            BananaJoe Most Active @liv-in-sky last edited by

            @liv-in-sky es gibt ja auch die Bluetooth-Version von Tasmota ... um z.B. diese Thermometer etc. abzufragen:
            https://tasmota.github.io/docs/Bluetooth_ESP32/#encryption-and-bind_key
            und die Befehle dazu https://tasmota.github.io/docs/Commands/#neopool

            So teuer sind die Sensoren ansonsten scheinbar nicht ...

            liv-in-sky 1 Reply Last reply Reply Quote 0
            • liv-in-sky
              liv-in-sky @BananaJoe last edited by

              @bananajoe

              du meinst, den sensor über bluetooth abfragen (ohne app) - das geht leider nicht. die haben eine sehr kurze (4- 5m ) reichweite - dh ich müßte in jedem zimmer einen bluetooth empfänger haben, der die daten des sensors empfangen kann. wie diese empfänger dann eingerichtet werden müssen, damit sie den sensor verstehen, weiß ch nicht

              ich habe auch so themometer , die über einen bluetooth empfänger (im stockwerk) abgefragt werden - da mußte ich aber einiges konfigurieren mit esphome

              1 Reply Last reply Reply Quote 0
              • liv-in-sky
                liv-in-sky last edited by liv-in-sky

                bin wieder einen schritt weiter - nutze jetzt einen esp32, da startet der sensor sofort

                @BananaJoe wenn ich in dem esp32 das bluetooth einschalte, werden mir sofort die thermometer aufgelistet - der radarsensor wird da nicht gezeigt - also über tasmota mit bt würde das nicht funktionieren

                jetzt muss ich nur noch die sensibilität hinbekommen - langsam geht was 🙂

                1 Reply Last reply Reply Quote 0
                • liv-in-sky
                  liv-in-sky last edited by liv-in-sky

                  @Zarello
                  @crunchip

                  bin mit dem sensor ein schrittchen weiter: esphome mit esp32 - die presence (motion) wird jetzt angezeigt - auch nach einem neustart des sensors

                  Image 010.png

                  esphome ist jetzt nicht gerade mein favourite - aber hier mal die yaml, die ich nutze. was nicht so toll ist, ist die reaktionszeit. als presence melder brauchbar - als trigger beim raumbetreten weniger - es sei den, wir finden noch ein paar einstellungen.
                  bei den yaml's müssen die gpio' eingestellt werden, je nach version des esp's (zeile 171 nicht vergessen).

                  esphome:
                   name: "ld2410m1"
                   platform : esp32
                   board: esp32dev
                  
                   
                   includes:
                     - uart_read_line_sensor_ld2410v3.h
                   on_boot:
                     priority: -100
                     then:
                       - script.execute: get_config
                  
                  # Enable logging
                  logger:
                   baud_rate: 0
                   logs:
                     sensor: INFO # DEBUG level with uart_target_output = overload!
                     binary_sensor: INFO
                     text_sensor: INFO
                  
                  # Enable Home Assistant API
                  api:
                  
                  ota:
                   
                  
                  wifi:
                   ssid: "Dragonxxxxxx1"
                   password: "xxxxxxxxxxxxxxxyy"
                   use_address: 192.168.178.86
                  
                  
                  
                  substitutions:
                   device_name: dev-sensor
                  
                  mqtt:
                   broker: 192.168.178.59
                   port: 1506
                   topic_prefix: ld2410motion/motion1
                   
                   
                  web_server:
                   port: 80
                   version: 2
                   include_internal: true
                   ota: false
                  
                  captive_portal:
                  
                  uart:
                   id: uart_bus
                   tx_pin:
                     number: GPIO1
                   rx_pin: 
                     number: GPIO3
                   baud_rate: 256000
                   parity: NONE
                   stop_bits: 1
                  
                  switch:
                   - platform: safe_mode
                     name: use_safe_mode
                     
                   - platform: template
                     name: configmode
                     id: configmode
                     optimistic: true
                     # assumed_state: false
                     turn_on_action:
                       # - switch.turn_off: engineering_mode
                       - lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(true);'
                       - delay: 100ms
                       - script.execute: clear_targets
                     turn_off_action:
                       - lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(false);'
                  
                   - platform: template
                     name: show_target_stats
                     id: show_stats
                     optimistic: true
                     internal: true
                     turn_off_action:
                       - script.execute: clear_targets
                  
                  text_sensor:
                   - platform: template
                     name: uptime_human_readable
                     id: uptime_human_readable
                     icon: mdi:clock-start
                     update_interval: 60s
                  
                  sensor:
                   - platform: uptime
                     name: uptime_sensor
                     id: uptime_sensor
                     update_interval: 60s
                     internal: true
                     on_raw_value:
                       then:
                         - text_sensor.template.publish:
                             id: uptime_human_readable
                             state: !lambda |-
                                       int seconds = round(id(uptime_sensor).raw_state);
                                       int days = seconds / (24 * 3600);
                                       seconds = seconds % (24 * 3600);
                                       int hours = seconds / 3600;
                                       seconds = seconds % 3600;
                                       int minutes = seconds /  60;
                                       seconds = seconds % 60;
                                       return (
                                         (days ? to_string(days)+":" : "00:") +
                                         (hours ? to_string(hours)+":" : "00:") +
                                         (minutes ? to_string(minutes)+":" : "00:") +
                                         (to_string(seconds))
                                       ).c_str();
                  
                   - platform: custom # currently crashes ESP32
                     lambda: |-
                       auto uart_component = static_cast<LD2410 *>(ld2410);
                       //return {uart_component->movingTargetDistance,uart_component->movingTargetEnergy,uart_component->stillTargetDistance,uart_component->stillTargetEnergy,uart_component->detectDistance};
                       return {};
                     sensors:
                     
                   - platform: template
                     name: movingTargetDistance
                     id: movingTargetDistance
                     unit_of_measurement: "cm"
                     accuracy_decimals: 0
                     internal: true
                     
                   - platform: template
                     name: movingTargetEnergy
                     id: movingTargetEnergy
                     unit_of_measurement: "%"
                     accuracy_decimals: 0
                     internal: true
                     
                   - platform: template
                     name: stillTargetDistance
                     id: stillTargetDistance
                     unit_of_measurement: "cm"
                     accuracy_decimals: 0
                     internal: true
                     
                   - platform: template
                     name: stillTargetEnergy
                     id: stillTargetEnergy
                     unit_of_measurement: "%"
                     accuracy_decimals: 0
                     internal: true
                     
                   - platform: template
                     name: detectDistance
                     id: detectDistance
                     unit_of_measurement: "cm"
                     accuracy_decimals: 0
                     internal: true
                     
                  custom_component:
                   - lambda: |-
                       return {new LD2410(id(uart_bus))};
                     components:
                       - id: ld2410
                       
                  binary_sensor:
                   - platform: gpio
                     name: mmwave_presence_ld2410
                     id: mmwave_presence_ld2410
                     pin: GPIO36
                     device_class: motion
                     on_state:
                       then:
                         - if: 
                             condition: 
                               - binary_sensor.is_off: mmwave_presence_ld2410
                             then: 
                               - delay: 150ms
                               - script.execute: clear_targets
                  
                  number:  
                   - platform: template
                     name: configMaxDistance
                     id: maxconfigDistance
                     unit_of_measurement: "M"
                     min_value: 0.75
                     max_value: 6
                     step: 0.75
                     update_interval: never
                     optimistic: true
                     set_action:
                       - switch.turn_on: configmode
                       - delay: 50ms
                       - lambda: |-
                           auto uart_component = static_cast<LD2410 *>(ld2410);
                           uart_component->setMaxDistancesAndNoneDuration(x/0.75,x/0.75,id(noneDuration).state);
                       - delay: 50ms
                       - lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
                       - delay: 50ms
                       - switch.turn_off: configmode
                  
                   - platform: template
                     name: "sensitivity_threshold_(%)"
                     id: allSensitivity
                     min_value: 10
                     max_value: 100
                     step: 5
                     mode: box
                     update_interval: never
                     optimistic: true
                     set_action:
                       - switch.turn_on: configmode
                       - delay: 50ms
                       - lambda: |-
                           auto uart_component = static_cast<LD2410 *>(ld2410);
                           uart_component->setAllSensitivity(x);
                       - delay: 50ms
                       - lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
                       - delay: 50ms
                       - switch.turn_off: configmode
                       
                   - platform: template
                     name: "motion_hold_(sec)"
                     id: noneDuration
                     min_value: 0
                     # max_value: 32767
                     max_value: 900
                     step: 1
                     mode: box
                     update_interval: never
                     optimistic: true
                     set_action:
                       - switch.turn_on: configmode
                       - delay: 50ms
                       - lambda: |-
                           auto uart_component = static_cast<LD2410 *>(ld2410);
                           uart_component->setMaxDistancesAndNoneDuration(id(maxconfigDistance).state, id(maxconfigDistance).state, x);
                       - delay: 50ms
                       - lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
                       - delay: 50ms
                       - switch.turn_off: configmode
                  button:
                   - platform: restart
                     name: "reset/restart_ESP/MCU"
                     entity_category: diagnostic
                     on_press:
                       - switch.turn_on: configmode
                       - delay: 50ms
                       - lambda: 'static_cast<LD2410 *>(ld2410)->factoryReset();'
                       - delay: 150ms
                       - lambda: 'static_cast<LD2410 *>(ld2410)->reboot();'
                       - delay: 150ms
                  
                  script:
                   - id: get_config
                     then:
                       - switch.turn_on: configmode
                       - delay: 500ms
                       - lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
                       - delay: 500ms
                       - switch.turn_off: configmode
                       
                   - id: clear_targets
                     then:
                       - lambda: |-
                           //id(hasTarget).publish_state(0);
                           //id(hasMovingTarget).publish_state(0);
                           //id(hasStillTarget).publish_state(0);
                           id(movingTargetDistance).publish_state(0);
                           id(movingTargetEnergy).publish_state(0);
                           id(stillTargetDistance).publish_state(0);
                           id(stillTargetEnergy).publish_state(0);
                           id(detectDistance).publish_state(0);
                  

                  und die def datei:

                  uart_read_line_sensor_ld2410v3.h

                  PS: dummerweise kommt es immer wieder zu kurzen fehlmedlungen bei dem presence dp

                  1 Reply Last reply Reply Quote 1
                  • liv-in-sky
                    liv-in-sky last edited by liv-in-sky

                    muss noch ein paar infos geben:

                    • man bekommt daten über mqtt, aber man keine settings ausführen - ich weiß nicht, wie man das ins yaml einfügen kann 😞
                    • um den sensor "grob" zu setzen, geht man über die api mit dem browser
                    <ip-adresse>:80
                    

                    Image 012.png

                    von hier: https://community.home-assistant.io/t/mmwave-wars-one-sensor-module-to-rule-them-all/453260

                    Zarello 1 Reply Last reply Reply Quote 0
                    • Zarello
                      Zarello @liv-in-sky last edited by

                      @liv-in-sky Ich habe die Zeit gefunden und etwas ein wenig was hinbekommen:
                      LD2410-ESP8266-Breadboard.jpg

                      Ich hatte am Anfang etwas Murks mit RX und TX gebaut, aber jetzt funktioniert's.
                      In ESP-Home habe ich erstmal den vorhandenen Sensor verwendet:

                      uart:
                        id: uart1
                        tx_pin: TX
                        rx_pin: RX
                        baud_rate: 256000
                        parity: NONE
                        stop_bits: 1
                      
                      ld2410:
                        timeout: 150s
                        max_move_distance : 6m
                        max_still_distance: 6m
                        g0_move_threshold: 50
                        g0_still_threshold: 50
                        g1_move_threshold: 50
                        g1_still_threshold: 50
                        g2_move_threshold: 50
                        g2_still_threshold: 51
                        g3_move_threshold: 50
                        g3_still_threshold: 51
                        g4_move_threshold: 50
                        g4_still_threshold: 51
                        g5_move_threshold: 50
                        g5_still_threshold: 51
                        g6_move_threshold: 40
                        g6_still_threshold: 41
                        g7_move_threshold: 40
                        g7_still_threshold: 41
                        g8_move_threshold: 40
                        g8_still_threshold: 41
                      
                      sensor:
                        - platform: ld2410
                          moving_distance:
                            name : Moving Distance
                          still_distance:
                            name: Still Distance
                          moving_energy:
                            name: Move Energy
                          still_energy:
                            name: Still Energy
                          detection_distance:
                            name: Detection Distance
                      
                      binary_sensor:
                        - platform: ld2410
                          has_target:
                            name: Presence
                          has_moving_target:
                            name: Moving Target
                          has_still_target:
                            name: Still Target
                      


                      Das funktioniert soweit erstmal (zum Teil). Was nicht funktioniert sind die Werte für "Still Target" und "Presence". Diese sind bei mir immer ON.
                      Außerdem ist es natürlich schade, dass man die Schwellwerte so im YAML angibt, dass soll natürlich über die Schnittstelle vom ioBroker eingestellt werden können.

                      d42820f5-96ee-4c15-bf3f-66fa33e672b2-grafik.png

                      Als nächstes werde ich mal Dein YAML ausprobieren.

                      liv-in-sky 1 Reply Last reply Reply Quote 0
                      • liv-in-sky
                        liv-in-sky @Zarello last edited by liv-in-sky

                        @zarello sagte in Tasmota Gitpod Sensor LD2410 BinFile:

                        Als nächstes werde ich mal Dein YAML ausprobieren.

                        ja - probier's mal - das läuft eigentlich ganz stabil bis jetzt - vielleicht kannst du das dann so umändern, das es über mqtt steuerbar ist

                        1 Reply Last reply Reply Quote 0
                        • liv-in-sky
                          liv-in-sky last edited by liv-in-sky

                          hier noch ein yaml für einen wemos D1 mini mit esphome - zeile 53 ff und 172 sind die pins definiert

                          • die pins zum anschliessen sind im yaml zu lesen
                          • die zusatzdatei https://forum.iobroker.net/post/957138 muss auch im system sein

                          esphome:
                           name: ld2410m3d1
                           includes:
                             - uart_read_line_sensor_ld2410v3.h
                           on_boot:
                              priority: -100
                              then:
                               - script.execute: get_config
                          
                          
                          esp8266:
                               board: esp01_1m
                          
                          
                          # Enable logging
                          logger:
                           baud_rate: 0
                           logs:
                             sensor: INFO # DEBUG level with uart_target_output = overload!
                             binary_sensor: INFO
                             text_sensor: INFO
                          
                          # Enable Home Assistant API
                          api:
                          
                          ota:
                           
                          
                          wifi:
                           ssid: "yyyyyyyyy1"
                           password: "xxxxxxxxxxxxxx2"
                           use_address: 192.168.178.67
                          
                          
                          
                          substitutions:
                           device_name: dev-sensor
                          
                          mqtt:
                           broker: 192.168.178.59
                           port: 1506
                           topic_prefix: ld2410motion/motion3
                           
                           
                          web_server:
                           port: 80
                           version: 2
                           include_internal: true
                           ota: false
                          
                          captive_portal:
                          
                          uart:
                           id: uart_bus
                           tx_pin:
                             number: GPIO1
                           rx_pin: 
                             number: GPIO3
                           baud_rate: 256000
                           parity: NONE
                           stop_bits: 1
                          
                          switch:
                           - platform: safe_mode
                             name: use_safe_mode
                             
                           - platform: template
                             name: configmode
                             id: configmode
                             optimistic: true
                             # assumed_state: false
                             turn_on_action:
                               # - switch.turn_off: engineering_mode
                               - lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(true);'
                               - delay: 100ms
                               - script.execute: clear_targets
                             turn_off_action:
                               - lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(false);'
                          
                           - platform: template
                             name: show_target_stats
                             id: show_stats
                             optimistic: true
                             internal: true
                             turn_off_action:
                               - script.execute: clear_targets
                          
                          text_sensor:
                           - platform: template
                             name: uptime_human_readable
                             id: uptime_human_readable
                             icon: mdi:clock-start
                             update_interval: 60s
                          
                          sensor:
                           - platform: uptime
                             name: uptime_sensor
                             id: uptime_sensor
                             update_interval: 60s
                             internal: true
                             on_raw_value:
                               then:
                                 - text_sensor.template.publish:
                                     id: uptime_human_readable
                                     state: !lambda |-
                                               int seconds = round(id(uptime_sensor).raw_state);
                                               int days = seconds / (24 * 3600);
                                               seconds = seconds % (24 * 3600);
                                               int hours = seconds / 3600;
                                               seconds = seconds % 3600;
                                               int minutes = seconds /  60;
                                               seconds = seconds % 60;
                                               return (
                                                 (days ? to_string(days)+":" : "00:") +
                                                 (hours ? to_string(hours)+":" : "00:") +
                                                 (minutes ? to_string(minutes)+":" : "00:") +
                                                 (to_string(seconds))
                                               ).c_str();
                          
                           - platform: custom # currently crashes ESP32
                             lambda: |-
                               auto uart_component = static_cast<LD2410 *>(ld2410);
                               //return {uart_component->movingTargetDistance,uart_component->movingTargetEnergy,uart_component->stillTargetDistance,uart_component->stillTargetEnergy,uart_component->detectDistance};
                               return {};
                             sensors:
                             
                           - platform: template
                             name: movingTargetDistance
                             id: movingTargetDistance
                             unit_of_measurement: "cm"
                             accuracy_decimals: 0
                             internal: true
                             
                           - platform: template
                             name: movingTargetEnergy
                             id: movingTargetEnergy
                             unit_of_measurement: "%"
                             accuracy_decimals: 0
                             internal: true
                             
                           - platform: template
                             name: stillTargetDistance
                             id: stillTargetDistance
                             unit_of_measurement: "cm"
                             accuracy_decimals: 0
                             internal: true
                             
                           - platform: template
                             name: stillTargetEnergy
                             id: stillTargetEnergy
                             unit_of_measurement: "%"
                             accuracy_decimals: 0
                             internal: true
                             
                           - platform: template
                             name: detectDistance
                             id: detectDistance
                             unit_of_measurement: "cm"
                             accuracy_decimals: 0
                             internal: true
                             
                          custom_component:
                           - lambda: |-
                               return {new LD2410(id(uart_bus))};
                             components:
                               - id: ld2410
                               
                          binary_sensor:
                           - platform: gpio
                             name: mmwave_presence_ld2410
                             id: mmwave_presence_ld2410
                             pin: GPIO5
                             device_class: motion
                             on_state:
                               then:
                                 - if: 
                                     condition: 
                                       - binary_sensor.is_off: mmwave_presence_ld2410
                                     then: 
                                       - delay: 150ms
                                       - script.execute: clear_targets
                          
                          number:  
                           - platform: template
                             name: configMaxDistance
                             id: maxconfigDistance
                             unit_of_measurement: "M"
                             min_value: 0.75
                             max_value: 6
                             step: 0.75
                             update_interval: never
                             optimistic: true
                             set_action:
                               - switch.turn_on: configmode
                               - delay: 50ms
                               - lambda: |-
                                   auto uart_component = static_cast<LD2410 *>(ld2410);
                                   uart_component->setMaxDistancesAndNoneDuration(x/0.75,x/0.75,id(noneDuration).state);
                               - delay: 50ms
                               - lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
                               - delay: 50ms
                               - switch.turn_off: configmode
                          
                           - platform: template
                             name: "sensitivity_threshold_(%)"
                             id: allSensitivity
                             min_value: 10
                             max_value: 100
                             step: 5
                             mode: box
                             update_interval: never
                             optimistic: true
                             set_action:
                               - switch.turn_on: configmode
                               - delay: 50ms
                               - lambda: |-
                                   auto uart_component = static_cast<LD2410 *>(ld2410);
                                   uart_component->setAllSensitivity(x);
                               - delay: 50ms
                               - lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
                               - delay: 50ms
                               - switch.turn_off: configmode
                               
                           - platform: template
                             name: "motion_hold_(sec)"
                             id: noneDuration
                             min_value: 0
                             # max_value: 32767
                             max_value: 900
                             step: 1
                             mode: box
                             update_interval: never
                             optimistic: true
                             set_action:
                               - switch.turn_on: configmode
                               - delay: 50ms
                               - lambda: |-
                                   auto uart_component = static_cast<LD2410 *>(ld2410);
                                   uart_component->setMaxDistancesAndNoneDuration(id(maxconfigDistance).state, id(maxconfigDistance).state, x);
                               - delay: 50ms
                               - lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
                               - delay: 50ms
                               - switch.turn_off: configmode
                          button:
                           - platform: restart
                             name: "reset/restart_ESP/MCU"
                             entity_category: diagnostic
                             on_press:
                               - switch.turn_on: configmode
                               - delay: 50ms
                               - lambda: 'static_cast<LD2410 *>(ld2410)->factoryReset();'
                               - delay: 150ms
                               - lambda: 'static_cast<LD2410 *>(ld2410)->reboot();'
                               - delay: 150ms
                          
                          script:
                           - id: get_config
                             then:
                               - switch.turn_on: configmode
                               - delay: 500ms
                               - lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
                               - delay: 500ms
                               - switch.turn_off: configmode
                               
                           - id: clear_targets
                             then:
                               - lambda: |-
                                   //id(hasTarget).publish_state(0);
                                   //id(hasMovingTarget).publish_state(0);
                                   //id(hasStillTarget).publish_state(0);
                                   id(movingTargetDistance).publish_state(0);
                                   id(movingTargetEnergy).publish_state(0);
                                   id(stillTargetDistance).publish_state(0);
                                   id(stillTargetEnergy).publish_state(0);
                                   id(detectDistance).publish_state(0);
                          

                          ich bin kein profi mit esphome - vielleicht habe ich das ganze etwas umständlich gemacht. hier eine kurze beschreibung:

                          • vorbereitendes yamls: name ändern, unter mqtt die richtigen daten eingeben

                          • die stromversorgung für den sensor nicht durch den esp nehmen, sondern den esp 5V und den sensor vcc parallel an der stromversorgung anschliessen - also nicht über den mini usb port anschliessen (nur zum flashen) -

                          • genutzt wird der esphome adapter

                          • die zusatzdatei uart_read_line_sensor_ld2410v3.h ins system kopieren: /opt/iobroker/iobroker-data/esphome.0

                          • dann ein standard esphome yaml für den esp erstellt unter: https://web.esphome.io/ und die wifi angaben machen - der esp wird dazu am usb port des pc's angeschlossen (die serielle-verbindung zwischen sensor und esp erst anschliessen, wenn das erste flashen vorbei ist - wenn noch am pc angeschlossen)

                          • die ip adresse habe ich dann im yaml eingetragen - unter wifi - use address

                          • der esp mit esphome wird anschliessend im adapter dashboard sichtbar - dann adapt drücken

                          • im esphome-dashboard auf edit drücken und das yaml hineinkopieren - sichern - installieren - der esp wird über wifi neu geflasht

                          war das erfolgreich müßte unter der ip adresse des esp eine webseite aufgehen, in der man das ganze konfigurieren kann

                          Image 014.png

                          dann testen, ob der esp richtige daten im mqtt ordner bringt

                          S 1 Reply Last reply Reply Quote 0
                          • liv-in-sky
                            liv-in-sky last edited by

                            also ich muss sagen, der sensor gefällt mir

                            habe einen raum sensorisch in 3 teile aufgeteilt - funktioniert gut

                            • man kann sozusagen licht steuern, wenn die anwesenheit einer person in einer ecke ist
                            • ist jmd in der dusche
                            • das licht in einem langen flur oder einer treppe steuern
                            • geht man zum fenster, wird außenlicht eingeschaltet

                            wer noch ideen hat - bitte her damit

                            Zarello RoboCop 2 Replies Last reply Reply Quote 0
                            • Zarello
                              Zarello @liv-in-sky last edited by Zarello

                              Kleiner Wasserstandsbericht von mir:
                              Wenn man sonst so gut wie nichts auf dem ESP8266 laufen lässt und auch die Stats nicht abholt, funktioniert der Sensor bei mir.
                              Sobald ein PWM für 'ne LED nebenbei laufen soll, kommt der ESP nicht mehr hinterher. Auch Updates funktionieren dann bei mir nur noch, wenn ich den LD2410 abklemme und den Sensor über USB aktualisiere. Über WLAN kann ich das dann komplett vergessen.
                              Es liegt möglicherweise auch daran, dass ich das Ganze etwas umgebaut habe, damit die maximalen Entfernungen für bewegte und bewegungslose Personen getrennt angegeben werden können und alle Sensitivitäten für die Bereiche getrennt angegeben werden können.

                              Bisher sind bei einem Neustart immer die eingestellten Werte wieder zurückgesetzt. Egal wie ich es probiert habe (ob vom LD2410 beim Start auslesen oder die Werte des ESPHome wieder zum Sensor schreiben) hat es bisher nicht funktionert, dass er seine Konfiguration behalten hat.

                              Da ich des öfteren Meldungen hatte, dass nicht mehr genug Speicher für eine Allokation vorhanden ist, habe ich sämtlichen dynamischen Speicherallokationen soweit wie möglich entfernt bzw. reduziert.

                              @liv-in-sky : Das Setzen der Werte von aussen über MQTT funktioniert übrigens über einen anderen Topic als das auslesen. Die Topics zum Setzen der Werte haben per Default am Ende command statt state. Leider muss man die erst erzeugen lassen indem man z.B. über die Kommandozeile ein entsprechenden Topic einfach postet.
                              (z.B.:mosquitto_pub -t ledtest/config/motion_hold_cmd -m 2 -- angepasst an die geänderten Topics, wie ich sie in meiner YAML verwendet habe).
                              Dann muss man noch in den Objekteigenschaften im MQTT-Bereich publish auf true setzen.

                              Hier erstmal meine Sourcen, wie sie zur Zeit bei mir rumliegen:

                              #include "esphome.h"
                              #include <iterator>
                              #include <deque>
                              
                              template<class T, unsigned size_>
                              class CyclicBuffer
                              {
                                size_t _start {0};
                                size_t _end {0};
                                bool _values_dropped {false};
                                std::array<T,size_> _buffer;
                              
                              public:
                                class iterator : public std::iterator<std::bidirectional_iterator_tag, T>
                                {
                                  CyclicBuffer& _b;
                                  size_t _pos;
                              
                                public:
                                  iterator (CyclicBuffer& b, size_t pos)
                                  : _b (b), _pos (pos) {};
                              
                                  // prefix++
                                  iterator& operator++ () { _pos = _pos+1; return *this; }
                                  iterator operator++ (int) { iterator i = *this; _pos = _pos+1; return i; }
                                  T& operator* () { return _b[_pos]; }
                                  T* operator-> () { return &(_b[_pos]); }
                                  bool operator== (const iterator& other) const { return _pos == other._pos; }
                                  bool operator!= (const iterator& other) const { return _pos != other._pos; }
                                };
                              
                                size_t size () const { return (_end + size_ - _start) % size_; }
                                iterator begin () { return iterator(*this, 0);}
                                iterator end () { return iterator(*this, (_end + size_ - _start) % size_);}
                                T& operator[] (size_t pos) { return _buffer[(_start+pos)%size_]; }
                                const T& operator[] (size_t pos) const { return _buffer[(_start+pos)%size_]; }
                              
                                void clear () { _end = _start; }
                              
                                void push_back (const T &v)
                                 {
                                  if (((_end + 1) % size_) == _start)
                                  {
                                    _values_dropped = true;
                                    return;
                                  }
                              
                                  _buffer[_end] = v;
                                  _end = (_end+1) % size_;
                                }
                              
                                void pop_front ()
                                {
                                  if (_start != _end)
                                    _start = (_start + 1) % size_;
                                }
                              };
                              
                              /*
                              TARGET EXAMPLE DATA
                              {F4:F3:F2:F1}:{0D:00}:{02}:{AA}: 02  : 4B:00:  4F  : 00:00 : 64   :  29:00 :{55}: {00} :{F8:F7:F6:F5}
                              {  header   }  {len}  {typ}{hd}{state}{mdist}{mval}{stadis}{staval}{decdis} {tl} {chck} {    MFR    }
                              */
                              typedef struct
                              {
                                  uint32_t MFR;
                                  uint16_t len;
                                  uint8_t type;                 // target or engineering
                                  uint8_t head;                // fixed head
                                  uint8_t state;              // state
                                  uint8_t movdist;          // movement distance
                                  uint8_t movdist2;          // movement distance
                                  uint8_t movval;           // movement energy value
                                  uint8_t stadist;        // stationary distance
                                  uint8_t stadist2;        // stationary distance
                                  uint8_t staval;         // stationary energy value
                                  uint8_t decdist;      // detection distance
                                  uint8_t decdist2;      // detection distance
                                  uint8_t tail;         // tail
                                  uint8_t chk;         // unused
                                  uint32_t MFR_end ;  // end
                              } TARGET;
                              
                              /*
                              CONF EXAMPLE DATA
                              FD:FC:FB:FA MFR[0-3]
                              1C:00 len[4-5]
                              61:01 CMD[6-7]
                              00:00 ACKstat[8-9]
                              AA Head [10]
                              08 maxDist [11]
                              06 maxMovDist[12]
                              06 maxStaDist[13]
                              1E:1E:1E:1E:1E:1E:1E:1E:1E:1E:1E:1E:1E:1E:1E:1E:1E:1E (9mov & 9sta sensitivities)
                              5A:00 none[32-33]
                              04:03:02:01[34-37]
                              */
                              typedef struct
                              {
                                  uint32_t MFR;
                                  uint16_t len;
                                  uint8_t cmd;
                                  uint8_t cmd_val;
                                  uint8_t ack_stat;
                                  uint8_t ack_stathigh;
                                  uint8_t head;
                                  uint8_t max_dist;
                                  uint8_t max_mov_dist;
                                  uint8_t max_sta_dist;
                                  uint8_t mov0sen;
                                  uint8_t mov1sen;
                                  uint8_t mov2sen;
                                  uint8_t mov3sen;
                                  uint8_t mov4sen;
                                  uint8_t mov5sen;
                                  uint8_t mov6sen;
                                  uint8_t mov7sen;
                                  uint8_t mov8sen;
                                  uint8_t sta0sen;
                                  uint8_t sta1sen;
                                  uint8_t sta2sen;
                                  uint8_t sta3sen;
                                  uint8_t sta4sen;
                                  uint8_t sta5sen;
                                  uint8_t sta6sen;
                                  uint8_t sta7sen;
                                  uint8_t sta8sen;
                                  uint16_t none;
                                  uint32_t MFR_end;
                              } CONF;
                              
                              class LD2410 : public Component, public UARTDevice
                              {
                              public:
                                //using BufferType = std::deque<uint8_t>;
                                using BufferType = CyclicBuffer<uint8_t, 120>;
                              
                                BufferType bytes;
                                const std::array<uint8_t, 6> config_header = {0xFD, 0xFC, 0xFB, 0xFA, 0x1C, 0x00};
                                const std::array<uint8_t, 6> target_header = {0xF4, 0xF3, 0xF2, 0xF1, 0x0D, 0x00};
                                const std::array<uint8_t, 6> ld2410_end_conf = {0x04, 0x03, 0x02, 0x01};
                              
                                LD2410(UARTComponent *parent);
                              
                                void setup() override;
                                void loop() override;
                              
                                void setConfigMode(bool confenable);
                                void setSensitivity(int gate, int senval_mov, int senval_sta);
                                void setMaxDistancesAndNoneDuration(int maxMovingDistanceRange, int maxStillDistanceRange, int noneDuration);
                                void queryParameters();
                                void restart();
                              
                              private:
                                void setMaxDistancesAndNoneDurationImpl(int maxMovingDistanceRange, int maxStillDistanceRange, int noneDuration);
                                void queryParametersImpl();
                                void factoryReset();
                                void reboot();
                                void ESP_LOGD_HEX(std::vector<uint8_t> bytes, uint8_t separator);
                                void sendCommand(char *commandStr, char *commandValue, int commandValueLen);
                                int twoByteToInt(char firstByte, char secondByte);
                                void handleTargetData(BufferType buffer);
                                void handleConfData(BufferType buffer);
                              
                                void setEngineeringMode(bool engenable);
                                void setSensitivityImpl(int gate, int senval_mov, int senval_sta);
                                void setBaudrate(int index);
                                bool doesHeaderMatch(BufferType bytes, std::array<uint8_t,6> header);
                              
                                typedef union
                                {
                                  TARGET target;
                                  uint8_t bytes[sizeof(TARGET)];
                                } TARGETUnion;
                              
                                typedef union
                                {
                                  CONF conf;
                                  uint8_t bytes[sizeof(CONF)];
                                } CONFUnion;
                              };
                              
                              LD2410::LD2410(UARTComponent *parent) : UARTDevice(parent)
                              {
                              }
                              
                              void LD2410::setup()
                              {
                                setConfigMode (true);
                              #if 0
                                setMaxDistancesAndNoneDurationImpl(id(maxconfigDistanceMoving).state / 0.75,
                                                                   id(maxconfigDistanceStill).state / 0.75,
                                                                   id(noneDuration).state);
                                setSensitivityImpl(0, id(sensitivity0Moving).state, id(sensitivity0Still).state);
                                setSensitivityImpl(1, id(sensitivity1Moving).state, id(sensitivity1Still).state);
                                setSensitivityImpl(2, id(sensitivity2Moving).state, id(sensitivity2Still).state);
                                setSensitivityImpl(3, id(sensitivity3Moving).state, id(sensitivity3Still).state);
                                setSensitivityImpl(4, id(sensitivity4Moving).state, id(sensitivity4Still).state);
                                setSensitivityImpl(5, id(sensitivity5Moving).state, id(sensitivity5Still).state);
                                setSensitivityImpl(6, id(sensitivity6Moving).state, id(sensitivity6Still).state);
                                setSensitivityImpl(7, id(sensitivity7Moving).state, id(sensitivity7Still).state);
                                setSensitivityImpl(8, id(sensitivity8Moving).state, id(sensitivity8Still).state);
                              #endif
                                queryParametersImpl();
                                setConfigMode (false);
                              }
                              
                              void LD2410::loop()
                              {
                                while (available())
                                {
                                  bytes.push_back(read());
                                  while (bytes.size() >= 6)
                                  {
                                    if (doesHeaderMatch(bytes, config_header))
                                    {
                                      if (bytes.size() < sizeof(CONF))
                                      {
                                        break;
                                      }
                                      handleConfData(bytes);
                                      bytes.clear();
                                    }
                                    else if (doesHeaderMatch(bytes, target_header)) {
                                      if (bytes.size() < sizeof(TARGET))
                                      {
                                        break;
                                      }
                                      handleTargetData(bytes);
                                      bytes.clear();
                                    }
                                    else
                                    {
                                      //ESP_LOGD("custom", "erase one byte");
                                      bytes.pop_front();
                                    }
                                  }
                                }
                              }
                              
                              void LD2410::ESP_LOGD_HEX(std::vector<uint8_t> bytes, uint8_t separator)
                              {
                                std::string res;
                                size_t len = bytes.size();
                                char buf[5];
                                for (size_t i = 0; i < len; i++) {
                                  if (i > 0) {
                                    res += separator;
                                  }
                                  sprintf(buf, "%02X", bytes[i]);
                                  res += buf;
                                }
                                ESP_LOGD("custom", "%s", res.c_str());
                              }
                              
                              void LD2410::sendCommand(char *commandStr, char *commandValue, int commandValueLen)
                              {
                                uint16_t len = 2;
                                if (commandValue != nullptr) {
                                  len += commandValueLen;
                                }
                                static std::vector<uint8_t> ld2410_conf = {0xFD, 0xFC, 0xFB, 0xFA};
                                size_t needed_size = 8 + (commandValue != nullptr ? commandValueLen : 0) + ld2410_end_conf.size ();
                                if (ld2410_conf.capacity () < needed_size)
                                  ld2410_conf.reserve (needed_size);
                              
                                ld2410_conf.resize (8);
                                ld2410_conf[4] = lowByte(len);
                                ld2410_conf[5] = highByte(len);
                                ld2410_conf[6] = commandStr[0];
                                ld2410_conf[7] = commandStr[1];
                              
                                if (commandValue != nullptr)
                                {
                                  for (int i = 0; i < commandValueLen; i++)
                                  {
                                    ld2410_conf.push_back(commandValue[i]);
                                  }
                                }
                                for (int i = 0; i < ld2410_end_conf.size(); i++) 
                                {
                                  ld2410_conf.push_back(ld2410_end_conf[i]);
                                }
                                // ESP_LOGD_HEX(ld2410_conf,':');
                                write_array(ld2410_conf);
                              }
                              
                              int LD2410::twoByteToInt(char firstByte, char secondByte)
                              {
                                return (int16_t)(secondByte << 8) + firstByte;
                              }
                              
                              void LD2410::handleTargetData(BufferType buffer)
                              {
                                static TARGETUnion targetUnion;
                                std::copy(buffer.begin(), buffer.end(), targetUnion.bytes);
                                if (id(show_stats).state == 1 && targetUnion.target.type == 0x02 && targetUnion.target.state != 0x00)
                                {
                                  int movdist = twoByteToInt(targetUnion.target.movdist, targetUnion.target.movdist2);
                                  if (id(movingTargetDistance).state != movdist)
                                  {
                                    id(movingTargetDistance).publish_state(movdist);
                                  }
                                  if (id(movingTargetEnergy).state != targetUnion.target.movval)
                                  {
                                    id(movingTargetEnergy).publish_state(targetUnion.target.movval);
                                  }
                                  int stadist = twoByteToInt(targetUnion.target.stadist, targetUnion.target.stadist2);
                                  if (id(stillTargetDistance).state != stadist)
                                  {
                                    id(stillTargetDistance).publish_state(stadist);
                                  }
                                  if (id(stillTargetEnergy).state != targetUnion.target.staval)
                                  {
                                    id(stillTargetEnergy).publish_state(targetUnion.target.staval);
                                  }
                                  int decdist = twoByteToInt(targetUnion.target.decdist, targetUnion.target.decdist2);
                                  if (id(detectDistance).state != decdist)
                                  {
                                    id(detectDistance).publish_state(decdist);
                                  }
                                }
                                else 
                                {
                                  return; 
                                }
                                // Engineering data - datasheet is horrible
                                // if (targetUnion.target.type == 0x01)
                                // }
                              }
                              
                              void LD2410::handleConfData(BufferType buffer)
                              {
                                static CONFUnion confUnion;
                                std::copy(buffer.begin(), buffer.end(), confUnion.bytes);
                                if (confUnion.conf.cmd == 0x61 && confUnion.conf.cmd_val == 0x01
                                    && confUnion.conf.ack_stat == 0x00 && confUnion.conf.head == 0xAA)
                                {
                                  id(maxconfigDistanceMoving).publish_state(float(confUnion.conf.max_mov_dist * 0.75));
                                  id(maxconfigDistanceStill).publish_state(float(confUnion.conf.max_sta_dist * 0.75));
                                  id(sensitivity0Moving).publish_state(confUnion.conf.mov0sen);
                                  id(sensitivity0Still).publish_state(confUnion.conf.sta0sen);
                                  id(sensitivity1Moving).publish_state(confUnion.conf.mov1sen);
                                  id(sensitivity1Still).publish_state(confUnion.conf.sta1sen);
                                  id(sensitivity2Moving).publish_state(confUnion.conf.mov2sen);
                                  id(sensitivity2Still).publish_state(confUnion.conf.sta2sen);
                                  id(sensitivity3Moving).publish_state(confUnion.conf.mov3sen);
                                  id(sensitivity3Still).publish_state(confUnion.conf.sta3sen);
                                  id(sensitivity4Moving).publish_state(confUnion.conf.mov4sen);
                                  id(sensitivity4Still).publish_state(confUnion.conf.sta4sen);
                                  id(sensitivity5Moving).publish_state(confUnion.conf.mov5sen);
                                  id(sensitivity5Still).publish_state(confUnion.conf.sta5sen);
                                  id(sensitivity6Moving).publish_state(confUnion.conf.mov6sen);
                                  id(sensitivity6Still).publish_state(confUnion.conf.sta6sen);
                                  id(sensitivity7Moving).publish_state(confUnion.conf.mov7sen);
                                  id(sensitivity7Still).publish_state(confUnion.conf.sta7sen);
                                  id(sensitivity8Moving).publish_state(confUnion.conf.mov8sen);
                                  id(sensitivity8Still).publish_state(confUnion.conf.sta8sen);
                                  id(noneDuration).publish_state(confUnion.conf.none);
                                }
                              }
                              
                              void LD2410::setConfigMode(bool confenable)
                              {
                                char cmd[2] = {char (confenable ? 0xFF : 0xFE),0x00};
                                char value[2] = {0x01, 0x00};
                                sendCommand(cmd, confenable ? value : nullptr, 2);
                              }
                              
                              void LD2410::queryParameters()
                              {
                                setConfigMode (true);
                                queryParametersImpl();
                                setConfigMode (false);
                              }
                              
                              void LD2410::queryParametersImpl()
                              {
                                char cmd_query[2] = {0x61, 0x00};
                                sendCommand(cmd_query, nullptr, 0);
                              }
                              
                              void LD2410::setEngineeringMode(bool engenable)
                              {
                                char cmd[2] = {char (engenable ? 0x62 : 0x63),0x00};
                                sendCommand(cmd, nullptr, 0);
                              }
                              
                              void LD2410::setMaxDistancesAndNoneDuration(int maxMovingDistanceRange, int maxStillDistanceRange, int noneDuration)
                              {
                                setConfigMode (true);
                                setMaxDistancesAndNoneDurationImpl(maxMovingDistanceRange, maxStillDistanceRange, noneDuration);
                                setConfigMode (false);
                              }
                              
                              void LD2410::setMaxDistancesAndNoneDurationImpl(int maxMovingDistanceRange, int maxStillDistanceRange, int noneDuration)
                              {
                                char cmd[2] = {0x60, 0x00};
                                char value[18] = {0x00, 0x00, lowByte(maxMovingDistanceRange), highByte(maxMovingDistanceRange), 0x00, 0x00,
                                                  0x01, 0x00, lowByte(maxStillDistanceRange), highByte(maxStillDistanceRange), 0x00, 0x00,
                                                  0x02, 0x00, lowByte(noneDuration), highByte(noneDuration), 0x00, 0x00};
                                sendCommand(cmd, value, sizeof(value));
                              }
                              
                              void LD2410::setSensitivityImpl(int gate, int senval_mov, int senval_sta)
                              {
                                ESP_LOGD("custom", "set sensitivity for gate %d to (%d / %d)", gate, senval_mov, senval_sta);
                                //  64 00  00 00  FF FF 00 00 01 00  28 00 00 00 02 00 28 00 00 00 04 03 02 01
                                // {cmd  }{dword}{   dgate  }{mword} {   mval   }{sword}{   sval   }{    MFR  }
                                char cmd[2] = {0x64, 0x00};
                                char value[18] = {0x00, 0x00, lowByte(gate), highByte(gate), 0x00, 0x00,
                                                  0x01, 0x00, lowByte(senval_mov), highByte(senval_mov), 0x00, 0x00,
                                                  0x02, 0x00, lowByte(senval_sta), highByte(senval_sta), 0x00, 0x00};
                                sendCommand(cmd, value, sizeof(value));
                              }
                              
                              void LD2410::setSensitivity(int gate, int senval_mov, int senval_sta)
                              {
                                setConfigMode (true);
                                setSensitivityImpl(gate, senval_mov, senval_sta);
                                setConfigMode (false);
                              }
                              
                              void LD2410::restart()
                              {
                                setConfigMode (true);
                                factoryReset ();
                                reboot ();
                              }
                              
                              void LD2410::factoryReset()
                              {
                                char cmd[2] = {0xA2, 0x00};
                                sendCommand(cmd, nullptr, 0);
                              }
                              
                              void LD2410::reboot()
                              {
                                char cmd[2] = {0xA3, 0x00};
                                sendCommand(cmd, nullptr, 0);
                                // not need to exit config mode because the ld2410 will reboot automatically
                              }
                              
                              void LD2410::setBaudrate(int index)
                              {
                                char cmd[2] = {0xA1, 0x00};
                                char value[2] = {char (index), 0x00};
                                sendCommand(cmd, value, sizeof(value));
                              }
                              
                              bool LD2410::doesHeaderMatch(BufferType bytes, std::array<uint8_t,6> header)
                              {
                                return std::equal(header.begin(), header.end(), bytes.begin());
                              }
                              

                              esphome:
                                name: led-test
                                friendly_name: led-test
                                includes:
                                  - uart_read_line_sensor_ld2410v3.h
                              #  on_boot:
                              #    priority: -100
                              #    then:
                              #      - script.execute: get_config
                              
                              
                              esp8266:
                                board: d1_mini
                              
                              wifi:
                                ssid: !secret wifi_ssid
                                password: !secret wifi_password
                              
                                # Enable fallback hotspot (captive portal) in case wifi connection fails
                                ap:
                                  ssid: !secret ap_ssid
                                  password: !secret ap_password
                              
                              ota:
                                password: !secret ota_password
                              
                              # Enable logging
                              logger:
                                baud_rate: 0
                              
                              web_server:
                                port: 80
                              
                              mqtt:
                                broker: 192.168.1.33
                                username: ledtest
                              #  password: !secret mqtt_password
                                topic_prefix: ledtest
                              
                              uart:
                                id: uart1
                                tx_pin: TX
                                rx_pin: RX
                                baud_rate: 256000
                                parity: NONE
                                stop_bits: 1
                              
                              #light:
                              #  - platform: monochromatic
                              #    name: "RGB-LED Red"
                              #    output: output_r
                              #  - platform: monochromatic
                              #    name: "RGB-LED Green"
                              #    output: output_g
                              #  - platform: monochromatic
                              #    name: "RGB-LED Blue"
                              #    output: output_b
                              
                              output:
                              #  - platform: esp8266_pwm
                              #    id: output_r
                              #    pin: D1
                              #    inverted: true
                              #    frequency: 50 Hz
                              #    #max_power: 50%
                              #  - platform: esp8266_pwm
                              #    id: output_g
                              #    pin: D2
                              #    inverted: true
                              #    frequency: 50 Hz
                              #    #max_power: 50%
                              #  - platform: esp8266_pwm
                              #    id: output_b
                              #    pin: D3
                              #    inverted: true
                              #    frequency: 50 Hz
                              #    #max_power: 50%
                                - platform: gpio
                                  pin: D1
                                  id: led_red
                                  inverted: true
                                - platform: gpio
                                  pin: D2
                                  id: led_green
                                  inverted: true
                                - platform: gpio
                                  pin: D3
                                  id: led_blue
                                  inverted: true
                              
                              captive_portal:
                              
                              switch:
                              # - platform: safe_mode
                              #   name: use_safe_mode
                                 
                               - platform: template
                                 name: configmode
                                 id: configmode
                                 optimistic: true
                                 # assumed_state: false
                                 internal: true
                                 turn_on_action:
                                   # - switch.turn_off: engineering_mode
                                   - lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(true);'
                                   - delay: 100ms
                                   - script.execute: clear_targets
                                 turn_off_action:
                                   - lambda: 'static_cast<LD2410 *>(ld2410)->setConfigMode(false);'
                              
                               - platform: template
                                 name: show_target_stats
                                 id: show_stats
                                 optimistic: true
                                 internal: false
                                 turn_off_action:
                                   - script.execute: clear_targets
                              
                              sensor:
                              #  - platform: wifi_signal
                              #    name: "Wifi Power"
                              #    update_interval: 10s
                              
                               - platform: template
                                 name: movingTargetDistance
                                 id: movingTargetDistance
                                 unit_of_measurement: "cm"
                                 accuracy_decimals: 0
                                 internal: false
                                 state_topic: ledtest/moveDistance
                                 
                               - platform: template
                                 name: movingTargetEnergy
                                 id: movingTargetEnergy
                                 unit_of_measurement: "%"
                                 accuracy_decimals: 0
                                 internal: false
                                 state_topic: ledtest/moveEnergy
                                 
                               - platform: template
                                 name: stillTargetDistance
                                 id: stillTargetDistance
                                 unit_of_measurement: "cm"
                                 accuracy_decimals: 0
                                 internal: false
                                 state_topic: ledtest/stillDistance
                                 
                               - platform: template
                                 name: stillTargetEnergy
                                 id: stillTargetEnergy
                                 unit_of_measurement: "%"
                                 accuracy_decimals: 0
                                 internal: false
                                 state_topic: ledtest/stillEnergy
                                 
                               - platform: template
                                 name: detectDistance
                                 id: detectDistance
                                 unit_of_measurement: "cm"
                                 accuracy_decimals: 0
                                 internal: false
                                 state_topic: ledtest/distance
                                 
                              custom_component:
                               - lambda: |-
                                   return {new LD2410(id(uart1))};
                                 components:
                                   - id: ld2410
                              
                              
                              binary_sensor:
                               - platform: gpio
                                 name: mmwave_presence_ld2410
                                 id: mmwave_presence_ld2410
                                 pin: D7
                                 device_class: motion
                                 state_topic: ledtest/occupancy
                                 on_state:
                                   then:
                                     - if: 
                                         condition: 
                                           - binary_sensor.is_off: mmwave_presence_ld2410
                                         then: 
                                           - delay: 150ms
                                           - script.execute: clear_targets
                                           - output.turn_off:
                                              id: led_blue
                                         else: 
                                           - output.turn_on:
                                              id: led_blue
                              
                              number:
                               - platform: template
                                 name: configMaxDistanceMoving
                                 id: maxconfigDistanceMoving
                                 unit_of_measurement: "M"
                                 min_value: 0.75
                                 max_value: 6
                                 step: 0.75
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/dist_max_move
                                 command_topic: ledtest/config/dist_max_move_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setMaxDistancesAndNoneDuration(x/0.75,id(maxconfigDistanceStill).state/0.75,id(noneDuration).state);
                              
                               - platform: template
                                 name: configMaxDistanceStill
                                 id: maxconfigDistanceStill
                                 unit_of_measurement: "M"
                                 min_value: 0.75
                                 max_value: 6
                                 step: 0.75
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/dist_max_still
                                 command_topic: ledtest/config/dist_max_still_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setMaxDistancesAndNoneDuration(id(maxconfigDistanceMoving).state/0.75,x/0.75,id(noneDuration).state);
                              
                               - platform: template
                                 name: "sensitivity_threshold_0_moving"
                                 id: sensitivity0Moving
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_0_move
                                 command_topic: ledtest/config/sens_threshold_0_move_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(0,x,id(sensitivity0Still).state);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_0_still"
                                 id: sensitivity0Still
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_0_still
                                 command_topic: ledtest/config/sens_threshold_0_still_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(0,id(sensitivity0Moving).state,x);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_1_moving"
                                 id: sensitivity1Moving
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_1_move
                                 command_topic: ledtest/config/sens_threshold_1_move_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(1,x,id(sensitivity1Still).state);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_1_still"
                                 id: sensitivity1Still
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_1_still
                                 command_topic: ledtest/config/sens_threshold_1_still_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(1,id(sensitivity1Moving).state,x);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_2_moving"
                                 id: sensitivity2Moving
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_2_move
                                 command_topic: ledtest/config/sens_threshold_2_move_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(2,x,id(sensitivity2Still).state);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_2_still"
                                 id: sensitivity2Still
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_2_still
                                 command_topic: ledtest/config/sens_threshold_2_still_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(2,id(sensitivity2Moving).state,x);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_3_moving"
                                 id: sensitivity3Moving
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_3_move
                                 command_topic: ledtest/config/sens_threshold_3_move_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(3,x,id(sensitivity3Still).state);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_3_still"
                                 id: sensitivity3Still
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_3_still
                                 command_topic: ledtest/config/sens_threshold_3_still_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(3,id(sensitivity3Moving).state,x);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_4_moving"
                                 id: sensitivity4Moving
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_4_move
                                 command_topic: ledtest/config/sens_threshold_4_move_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(4,x,id(sensitivity4Still).state);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_4_still"
                                 id: sensitivity4Still
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_4_still
                                 command_topic: ledtest/config/sens_threshold_4_still_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(4,id(sensitivity4Moving).state,x);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_5_moving"
                                 id: sensitivity5Moving
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_5_move
                                 command_topic: ledtest/config/sens_threshold_5_move_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(5,x,id(sensitivity5Still).state);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_5_still"
                                 id: sensitivity5Still
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_5_still
                                 command_topic: ledtest/config/sens_threshold_5_still_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(5,id(sensitivity5Moving).state,x);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_6_moving"
                                 id: sensitivity6Moving
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_6_move
                                 command_topic: ledtest/config/sens_threshold_6_move_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(6,x,id(sensitivity6Still).state);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_6_still"
                                 id: sensitivity6Still
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_6_still
                                 command_topic: ledtest/config/sens_threshold_6_still_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(6,id(sensitivity6Moving).state,x);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_7_moving"
                                 id: sensitivity7Moving
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_7_move
                                 command_topic: ledtest/config/sens_threshold_7_move_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(7,x,id(sensitivity7Still).state);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_7_still"
                                 id: sensitivity7Still
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_7_still
                                 command_topic: ledtest/config/sens_threshold_7_still_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(7,id(sensitivity7Moving).state,x);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_8_moving"
                                 id: sensitivity8Moving
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_8_move
                                 command_topic: ledtest/config/sens_threshold_8_move_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(8,x,id(sensitivity8Still).state);
                                   
                               - platform: template
                                 name: "sensitivity_threshold_8_still"
                                 id: sensitivity8Still
                                 min_value: 10
                                 max_value: 100
                                 step: 5
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/sens_threshold_8_still
                                 command_topic: ledtest/config/sens_threshold_8_still_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setSensitivity(8,id(sensitivity8Moving).state,x);
                                   
                               - platform: template
                                 name: "motion_hold_(sec)"
                                 id: noneDuration
                                 min_value: 0
                                 max_value: 900
                                 step: 1
                                 mode: box
                                 update_interval: never
                                 optimistic: true
                                 state_topic: ledtest/config/motion_hold
                                 command_topic: ledtest/config/motion_hold_cmd
                                 on_value:
                                   - lambda: |-
                                       auto uart_component = static_cast<LD2410 *>(ld2410);
                                       uart_component->setMaxDistancesAndNoneDuration(id(maxconfigDistanceMoving).state, id(maxconfigDistanceStill).state, x);
                              
                              button:
                               - platform: restart
                                 name: "reset/restart_ESP/MCU"
                                 entity_category: diagnostic
                                 on_press:
                                   - lambda: 'static_cast<LD2410 *>(ld2410)->restart();'
                              
                               - platform: template
                                 name: "queryParameters"
                                 #entity_category: diagnostic
                                 on_press:
                                   - lambda: 'static_cast<LD2410 *>(ld2410)->queryParameters();'
                              
                              script:
                               - id: clear_targets
                                 then:
                                   - lambda: |-
                                       //id(hasTarget).publish_state(0);
                                       //id(hasMovingTarget).publish_state(0);
                                       //id(hasStillTarget).publish_state(0);
                                       id(movingTargetDistance).publish_state(0);
                                       id(movingTargetEnergy).publish_state(0);
                                       id(stillTargetDistance).publish_state(0);
                                       id(stillTargetEnergy).publish_state(0);
                                       id(detectDistance).publish_state(0);
                              

                              Falls jemand übrigens weiß, wie man im YAML Variablen benutzt oder womöglich sogar Schleifen programmiert, da hätte ich gesteigertes Interesse 😉
                              Schleife meint hier nicht eine Schleife in einem Lambda sondern mehrere number - plattform: template Einträge, die sich nur duch wenige Einträge voneinander unterscheiden. Siehe im obigen YAML die Einträge mit den IDs sensitivity[0-8](Still|Moving).

                              liv-in-sky 1 Reply Last reply Reply Quote 0
                              • liv-in-sky
                                liv-in-sky @Zarello last edited by

                                erstmal danke, dass du weiter testest

                                Bisher sind bei einem Neustart immer die eingestellten Werte wieder zurückgesetzt.

                                bei dem yaml, welches ich gepostet habe, bleibt das setting - wie das im yaml gemacht wird, weiß ich nicht

                                mit esp32 hatte ich als erstes geschafft, ein stabiles yaml zu bekommen - war verwundert, aber auch das yaml für den wemos d1 mini läuft stabil

                                Zarello 1 Reply Last reply Reply Quote 0
                                • BananaJoe
                                  BananaJoe Most Active last edited by BananaJoe

                                  @zarello sagte in Tasmota ESPHome Presence Sensor LD2410:

                                  Leider muss man die erst erzeugen lassen indem man z.B. über die Kommandozeile ein entsprechenden Topic einfach postet.
                                  (z.B.:mosquitto_pub -t ledtest/config/motion_hold_cmd -m 2 -- angepasst an die geänderten Topics, wie ich sie in meiner YAML verwendet habe).
                                  Dann muss man noch in den Objekteigenschaften im MQTT-Bereich publish auf true setzen.

                                  Du kannst auch mit sendTo arbeiten, dann wird das Topic auch angelegt und ist nutzbar (hab ich diverse mal für Tasmota gebraucht da außer dem POWER unter cmnd in der Regel nicht angelegt wird, Tasmota aber ja auf alle bekannten Befehle dort lauscht):

                                  // Beispiel für SendTo von https://github.com/ioBroker/ioBroker.mqtt
                                  // Test ob ich das zum Anlegen von neuen MQTT-Topics etc. nutzen kann
                                  /*
                                   * @param {string}  MQTT instance     Specify MQTT instance to send message through (may be either server or client)
                                   * @param {string}  action            Action to use (always 'sendMessage2Client' for sending plain messages)
                                   * @param {object}  payload         
                                   * @param {string}  payload.topic     Topic to publish message on
                                   * @param {string}  payload.message   Message to be published on specified topic
                                   *
                                   */
                                  sendTo('mqtt.0', 'sendMessage2Client', {topic: 'znil/Tests/Testnachricht', message: '42'});
                                  

                                  im MQTT-Adapter den ich als Client für einen Mosquitto einsetze sind ansonsten alle Haken raus:
                                  8eb2d491-8b1f-4d14-b7c0-c2601bb64b14-image.png

                                  So kann man bei Bedarf die "MQTT-Datenpunkte" damit anlegen. Oder gleich im Skript immer mit sendTo arbeiten
                                  Bei Bedarf hätte ich auch ein Blockly-Beispiel

                                  Das ganz habe ich in der Hilfe zum MQTT-Adapter gefunden (auch wenn da nicht steht das man es zum anlegen nutzen soll)

                                  Zarello 1 Reply Last reply Reply Quote 1
                                  • Zarello
                                    Zarello @BananaJoe last edited by

                                    @bananajoe sagte in Tasmota ESPHome Presence Sensor LD2410:

                                    Du kannst auch mit sendTo arbeiten, dann wird das Topic auch angelegt

                                    sendTo('mqtt.0', 'sendMessage2Client', {topic: 'znil/Tests/Testnachricht', message: '42'});
                                    

                                    Schade, mit dem mqtt-client Adapter scheint das nicht zu funktionieren - getestet mit 'mqtt-client.0' als Ziel.
                                    Jetzt muss ich mir wohl überlegen, ob ich den normalen mqtt Adapter verwenden möchte und alle Datenpunkte umziehen möchte.

                                    1 Reply Last reply Reply Quote 0
                                    • Zarello
                                      Zarello @liv-in-sky last edited by

                                      @liv-in-sky sagte in Tasmota ESPHome Presence Sensor LD2410:

                                      bei dem yaml, welches ich gepostet habe, bleibt das setting - wie das im yaml gemacht wird, weiß ich nicht

                                      Ich habe da ein bisschen in der setup Methode in der Header-Datei rumgespielt.
                                      Inzwischen habe ich festgestellt, so wie es jetzt ist bleiben bei Strom aus und wieder an die Settings erhalten.
                                      Nur wenn ich eine neue Software aufspiele hat er wieder seine Default-Werte. Das wundert mich, denn eigentlich hole ich die Werte am Anfang vom Sensor. Eine neue Software sollte für den Sensor ja nichts anderes sein als aus- und wieder einschalten. Evtl. wird aber irgendwo noch der Reset aufgerufen. Den werde ich mal abklemmen.

                                      Außerdem wird bei mir der Wert für stillTargetDistance niemals geändert. Der bleibt einfach auf 0.
                                      Bekommst Du da sinnvolle Werte?

                                      liv-in-sky 1 Reply Last reply Reply Quote 0
                                      • liv-in-sky
                                        liv-in-sky @Zarello last edited by liv-in-sky

                                        @zarello sagte in Tasmota ESPHome Presence Sensor LD2410:

                                        stillTargetDistance

                                        bei mir auch nicht - steht in der webgui , bleibt aber immer 0 - auch kein mqtt datenpunkt

                                        ich konzentriere mich aber auf den presence dp - mehr brauche ich eigentlich nicht (oder ich weiß noch nicht, dass ich ihn brauche

                                        Zarello 1 Reply Last reply Reply Quote 0
                                        • Zarello
                                          Zarello @liv-in-sky last edited by

                                          Idee wäre, über zwei Geräte aus den Abständen die Position zu ermitteln. Aber ich vermute, dass wird sowieso nicht funktionieren, da zwei Geräte in einem Raum sich höchstwahrscheinlich gegenseitig stören.
                                          Die müsste man dann synchronisieren und immer eines der beiden ausschalten, allerdings bieten die Geräte diese Option nicht und wenn man ihnen einfach den Strom klaut, funktionieren sie vermutlich nicht mehr so gut, denn nach meinen Beobachtungen funktioniert die Detektion von unbewegten Personen nur, wenn sie vorher als bewegt erkannt wurden.
                                          Wenn man sich im Sensorbereich komplett still verhält (Atem anhalten), kann man danach normal atmen ohne, dass der Sensor anschlägt. Erst wenn man sich wieder etwas mehr bewegt und der Sensor das erkennt, bleibt er danach auch aktiv, wenn man nur atmet.

                                          liv-in-sky 1 Reply Last reply Reply Quote 0
                                          • S
                                            Stadtschloss @liv-in-sky last edited by Stadtschloss

                                            @liv-in-sky Danke für das Script! Leider bleibt bei mir der Wert "mmwave_presence_ld2410" immer auf ON. Auch nach den abgelaufenen 5 Sekunden wo keine Bewegung passiert.

                                            Edit: Ah okay musst noch die Out vom Sensor an den D1 anlöten 🙂

                                            liv-in-sky 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            905
                                            Online

                                            31.7k
                                            Users

                                            79.7k
                                            Topics

                                            1.3m
                                            Posts

                                            17
                                            187
                                            27935
                                            Loading More Posts
                                            • Oldest to Newest
                                            • Newest to Oldest
                                            • Most Votes
                                            Reply
                                            • Reply as topic
                                            Log in to reply
                                            Community
                                            Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                            The ioBroker Community 2014-2023
                                            logo