puck to Home Assistant via ESPHome

Posted on
  • Hi everyone
    I am trying to find the most efficient way to get data from puck.js to ESPHome.
    End goal is to get it into Home Assistant. I have other sensors running off ESPHome (ESP32), so makes sense to re-use it to get the data.
    Any tips on the service data format? I am sending battery status of puck plus 3 extra pieces of info

  • Did you have any success with this? What device type/config are you using on ESPHome and the ESP32 to get the data in?

    It's something I'm interested in doing myself so might be able to be some help.

  • Hi, sorry, just saw your reply.
    I got it working OK. Maybe not the best way, but had to work around the things that I do understand and examples I found online =)

    captive_portal:
    
    esp32_ble_tracker:
      on_ble_service_data_advertise:
        - mac_address: E9:F5:D3:BB:1C:30
          service_uuid: 180F
          then:
            - lambda: 'id(PowerMeter_sensor_battery).publish_state(x[0]);'
    
        - mac_address: E9:F5:D3:BB:1C:30
          service_uuid: "1809"
          then:
            - lambda: 'id(PowerMeter_sensor_temperature).publish_state(x[0]);'
         
            
        - mac_address: E9:F5:D3:BB:1C:30
          service_uuid: 2A03
          then:
            - lambda: |-
                std::string b(x.begin(), x.end());
                std::string myStr = &b[0];
                float num_float = parse_float(myStr).value();
                ESP_LOGD("PowerMeter_sensor_instant_power:", "%s", &b[0] );
                id(PowerMeter_sensor_instant_power).publish_state(num_float);
                
        - mac_address: E9:F5:D3:BB:1C:30
          service_uuid: 2A04
          then:
            - lambda: |-
                std::string b(x.begin(), x.end());
                std::string myStr = &b[0];
                float num_float = parse_float(myStr).value();
                ESP_LOGD("PowerMeter_sensor_pulse_hour:", "%s", &b[0] );
                id(PowerMeter_sensor_pulse_hour).publish_state(num_float);      
    
        - mac_address: E9:F5:D3:BB:1C:30
          service_uuid: 2A05
          then:
            - lambda: |-
                std::string b(x.begin(), x.end());
                std::string myStr = &b[0];
                float num_float = parse_float(myStr).value();    
                ESP_LOGD("PowerMeter_sensor_pulse_day:", "%s", &b[0] );
                id(PowerMeter_sensor_pulse_day).publish_state(num_float);      
    
                
      on_ble_advertise:
          then:
            - lambda: |-
                ESP_LOGD("ble_adv", "New BLE device");
                ESP_LOGD("ble_adv", "  address: %s", x.address_str().c_str());
                ESP_LOGD("ble_adv", "  name: %s", x.get_name().c_str());
                ESP_LOGD("ble_adv", "  RSSI: %i", x.get_rssi());
                ESP_LOGD("ble_adv", "  Advertised service UUIDs:");
                for (auto uuid : x.get_service_uuids()) {
                    ESP_LOGD("ble_adv", "    - %s", uuid.to_string().c_str());
                }
                ESP_LOGD("ble_adv", "  Advertised service data:");
                for (auto data : x.get_service_datas()) {
                    ESP_LOGD("ble_adv", "    - %s: (length %i)", data.uuid.to_string().c_str(), data.data.size());
                    
                }
                ESP_LOGD("ble_adv", "  Advertised manufacturer data:");
                for (auto data : x.get_manufacturer_datas()) {
                    ESP_LOGD("ble_adv", "    - %s: (length %i)", data.uuid.to_string().c_str(), data.data.size());
                }
                if(x.get_ibeacon().has_value()) {
                  auto ibeacon = x.get_ibeacon().value();
                  ESP_LOGD("ble_adv", ibeacon.get_uuid().to_string().c_str());
                  ESP_LOGD("ble_adv", "Major: %i", ibeacon.get_major());
                  ESP_LOGD("ble_adv", "Minor: %i", ibeacon.get_minor());
                }
    
    sensor:
      - platform: template
        name: "PowerMeter_sensor_battery"
        id: PowerMeter_sensor_battery
        device_class: "battery"
        unit_of_measurement: "%"
      - platform: template
        name: "PowerMeter_sensor_temperature"
        id: PowerMeter_sensor_temperature
        device_class: "temperature"
        unit_of_measurement: "°C"
      - platform: template
        name: "PowerMeter_sensor_instant_power"
        id: PowerMeter_sensor_instant_power
        unit_of_measurement: "Wh"
        device_class: "energy"
      - platform: template
        name: "PowerMeter_sensor_pulse_hour"
        id: PowerMeter_sensor_pulse_hour
        unit_of_measurement: "Wh"
        device_class: "energy"
      - platform: template
        name: "PowerMeter_sensor_pulse_day"
        id: PowerMeter_sensor_pulse_day    
        unit_of_measurement: "Wh"
        device_class: "energy"
    
  • That's great - thanks for posting that ESPHome code. I hadn't seen any examples of that before so it's great to be able to see something complete.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

puck to Home Assistant via ESPHome

Posted by Avatar for user130485 @user130485

Actions