Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
projects:internetofthings:esphome [2021/02/18 16:29] – [BLE bluetooth tracker] scipio | projects:internetofthings:esphome [2021/07/06 07:26] (current) – [ESP32 cam] scipio | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== ESPHOME ====== | ====== ESPHOME ====== | ||
+ | ===== ESP32 cam ===== | ||
- | ===== BLE bluetooth tracker ===== | + | * [[https:// |
+ | |||
+ | |||
+ | |||
+ | <code bash> | ||
+ | #!/bin/sh | ||
+ | |||
+ | TOKEN=... | ||
+ | |||
+ | PAYLOAD=" | ||
+ | |||
+ | |||
+ | curl -q -X POST \ | ||
+ | -d " | ||
+ | -H " | ||
+ | -H " | ||
+ | http:// | ||
+ | </ | ||
+ | |||
+ | in esp32 cam this section is missing in " | ||
+ | <code javascript> | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | } | ||
+ | ] | ||
+ | }, | ||
+ | </ | ||
+ | |||
+ | esp32 entry (missing some values) | ||
+ | |||
+ | <code javascript> | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | } | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | }, | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | valid stream camera working in alexa | ||
+ | <code javascript> | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | ] | ||
+ | } | ||
+ | ] | ||
+ | }, | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | } | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | }, | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ] | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | ===== BLE tracker smartband ===== | ||
+ | |||
+ | ==== esphome ==== | ||
+ | |||
+ | enable esp32_ble_tracker and a binary sensor on ble_presence | ||
+ | < | ||
+ | esp32_ble_tracker: | ||
+ | |||
+ | binary_sensor: | ||
+ | - platform: ble_presence | ||
+ | mac_address: | ||
+ | id: miband_presence_scipio | ||
+ | name: " | ||
+ | </ | ||
+ | |||
+ | ==== hass ==== | ||
+ | |||
+ | automation directly on sensor created by esphome | ||
+ | < | ||
+ | - alias: cancello | ||
+ | trigger: | ||
+ | - entity_id: binary_sensor.miband_presence_scipio | ||
+ | platform: state | ||
+ | to: ' | ||
+ | for: | ||
+ | seconds: 2 | ||
+ | - entity_id: binary_sensor.miband_presence_scipio | ||
+ | platform: state | ||
+ | to: ' | ||
+ | for: | ||
+ | seconds: 2 | ||
+ | action: | ||
+ | - service: notify.alexa_media | ||
+ | data_template: | ||
+ | message: > | ||
+ | {% if is_state(' | ||
+ | ' | ||
+ | {% else %} | ||
+ | ' | ||
+ | {% endif %} | ||
+ | data: | ||
+ | type: announce | ||
+ | method: all | ||
+ | target: | ||
+ | - show | ||
+ | - Echo | ||
+ | </ | ||
+ | |||
+ | |||
+ | example of added binary sensor defined on ble sensor | ||
+ | < | ||
+ | binary_sensor: | ||
+ | - platform: template | ||
+ | sensors: | ||
+ | miband_scipio_sticky: | ||
+ | value_template: | ||
+ | {{is_state(' | ||
+ | delay_off: 60 | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== BLE bluetooth tracker (version 1) ===== | ||
+ | |||
+ | hass input_boolean: | ||
+ | <code yaml> | ||
+ | beacon2_learn: | ||
+ | name: learn beacon2 | ||
+ | initial: off | ||
+ | icon: mdi: | ||
+ | |||
+ | beacon2_active: | ||
+ | name: beacon2 is recently seen | ||
+ | icon: mdi: | ||
+ | |||
+ | beacon2_trigger: | ||
+ | name: beacon2 is now detected | ||
+ | initial: off | ||
+ | icon: mdi: | ||
+ | </ | ||
+ | |||
+ | hass input_text: | ||
+ | < | ||
+ | beacon1: | ||
+ | name: BLE beacon1 | ||
+ | |||
+ | beacon2: | ||
+ | name: BLE beacon2 | ||
+ | </ | ||
+ | |||
+ | hass scripts: | ||
+ | < | ||
+ | set_ibeacon: | ||
+ | sequence: | ||
+ | - condition: template | ||
+ | value_template: | ||
+ | - service: script.set_beacon1 | ||
+ | data_template: | ||
+ | ibeacon: "{{ ibeacon }}" | ||
+ | - service: script.set_beacon2 | ||
+ | data_template: | ||
+ | ibeacon: "{{ ibeacon }}" | ||
+ | |||
+ | set_beacon2: | ||
+ | sequence: | ||
+ | - service: script.beacon2_active | ||
+ | data_template: | ||
+ | ibeacon: "{{ ibeacon }}" | ||
+ | - condition: state | ||
+ | entity_id: input_boolean.beacon2_learn | ||
+ | state: " | ||
+ | - service: input_text.set_value | ||
+ | data_template: | ||
+ | entity_id: input_text.beacon2 | ||
+ | value: "{{ ibeacon }}" | ||
+ | - service: input_boolean.turn_off | ||
+ | entity_id: input_boolean.beacon2_learn | ||
+ | |||
+ | beacon2_active: | ||
+ | sequence: | ||
+ | - condition: template | ||
+ | value_template: | ||
+ | - service: input_boolean.turn_on | ||
+ | entity_id: input_boolean.beacon2_trigger | ||
+ | - delay: 1 | ||
+ | - service: input_boolean.turn_off | ||
+ | entity_id: input_boolean.beacon2_trigger | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | hass automations: | ||
+ | < | ||
+ | - alias: " | ||
+ | trigger: | ||
+ | platform: state | ||
+ | entity_id: input_sensor.beacon2_trigger | ||
+ | to: " | ||
+ | condition: | ||
+ | condition: state | ||
+ | entity_id: input_boolean.beacon2_active | ||
+ | state: " | ||
+ | action: | ||
+ | - service: input_boolean.turn_on | ||
+ | entity_id: input_boolean.beacon2_active | ||
+ | - service: notify.alexa_media | ||
+ | data: | ||
+ | message: " | ||
+ | data: | ||
+ | type: announce | ||
+ | method: all | ||
+ | target: | ||
+ | - show | ||
+ | - Echo | ||
+ | |||
+ | - alias: " | ||
+ | trigger: | ||
+ | platform: state | ||
+ | entity_id: input_boolean.beacon2_trigger | ||
+ | to: " | ||
+ | for: 140 | ||
+ | action: | ||
+ | - service: input_boolean.turn_off | ||
+ | entity_id: input_boolean.beacon2_active | ||
+ | - service: notify.alexa_media | ||
+ | data: | ||
+ | message: " | ||
+ | data: | ||
+ | type: announce | ||
+ | method: all | ||
+ | target: | ||
+ | - show | ||
+ | - Echo | ||
+ | </ | ||
+ | |||
+ | panel | ||
+ | <code yaml> | ||
+ | type: entities | ||
+ | entities: | ||
+ | - entity: input_boolean.beacon2_learn | ||
+ | - entity: input_text.beacon2 | ||
+ | - entity: input_boolean.beacon2_trigger | ||
+ | - entity: input_boolean.beacon2_active | ||
+ | title: Tracker cancello | ||
+ | </ | ||
+ | |||
+ | esphome | ||
+ | <code yaml> | ||
+ | esp32_ble_tracker: | ||
+ | on_ble_advertise: | ||
+ | - then: | ||
+ | - homeassistant.service: | ||
+ | service: script.set_ibeacon | ||
+ | data: | ||
+ | ibeacon: !lambda |- | ||
+ | for (auto data : x.get_manufacturer_datas()) { | ||
+ | auto message = hexencode(data.data); | ||
+ | ESP_LOGD(" | ||
+ | if (message.size() >= 73) { | ||
+ | /* ibeacon = e2c56db5-dffb-48d2-b060-d0f5a71096e0 */ | ||
+ | auto ibeacon = message.substr(6, | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | return ibeacon.c_str(); | ||
+ | } | ||
+ | } | ||
+ | return ""; | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== BLE bluetooth tracker (version 2) ===== | ||
+ | <code yaml> | ||
+ | text_sensor: | ||
+ | - platform: template | ||
+ | name: "BLE ibeacon" | ||
+ | id: template_text | ||
+ | |||
+ | |||
+ | esp32_ble_tracker: | ||
+ | on_ble_advertise: | ||
+ | - then: | ||
+ | - lambda: |- | ||
+ | for (auto data : x.get_manufacturer_datas()) { | ||
+ | auto message = hexencode(data.data); | ||
+ | ESP_LOGD(" | ||
+ | if (message.size() >= 73) { | ||
+ | /* ibeacon = e2c56db5-dffb-48d2-b060-d0f5a71096e0 */ | ||
+ | auto ibeacon = message.substr(6, | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | id(template_text).publish_state(ibeacon.c_str()); | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== BLE bluetooth tracker | ||
parameters to change: | parameters to change: | ||
Line 45: | Line 449: | ||
</ | </ | ||
+ | |||
+ | |||
+ | |||
+ |