animavitis
(Animavitis)
October 10, 2018, 5:28pm
1
Hi
I want to use ESP32 boards with ble_rssi component with home assistant MQTT Room Presence . For this i need to send custom payload from esphomeyaml. Was trying for some time but without succes. Maybe someone here have better C++ knowledge and can help me with this??
My code that can send RSSI value to custom Topic
- platform: ble_rssi
mac_address: 84:A4:66:89:75:8E
name: "beacon"
id: rssi_beacon
on_value:
- mqtt.publish:
topic: home_presence
payload: !lambda >-
char[3] rssi;
double rssitemp=id(rssi_sygonix).value;
dtostrf(rssitemp, 2, 0, rssi);
return rssi;
This code will send RSSI value to Payload, i payload like this:
{
"id": "84:A4:66:89:75:8E",
"name": "beacon",
"distance": 78
}
Any ideas??
1 Like
animavitis
(Animavitis)
October 11, 2018, 8:17pm
2
Was able to make it works
- platform: ble_rssi
mac_address: 84:A4:66:89:75:8E
name: "Beacon"
id: rssi_beacon
on_value:
- mqtt.publish:
topic: home_presence/room_1
payload: !lambda >-
double ratio = id(rssi_sygonix).value/-59;
double distancetemp = (0.89)* pow(ratio,7.7095) + 0.11;
char distance[sizeof(distancetemp)+1];
dtostrf(distancetemp,2,3,distance);
std::string payload;
payload.append("{\"id\":\"84:A4:66:89:75:8E\",\"name\":\"Beacon\",\"distance\":");
payload.append(distance);
payload.append("}");
return payload;```
btw. now im sending calculated distance (not RSSI) in payload
2 Likes
animavitis
(Animavitis)
October 25, 2018, 2:22pm
3
in version 1.9 u can publish mqtt message via mqtt.publish_json action:
…
- platform: ble_rssi
mac_address: 84:A4:66:89:75:8E
name: “Sygonix”
id: rssi_sygonix
on_value:
- mqtt.publish_json:
topic: home_presence/room_1
payload: |-
root[“id”] = “84:A4:66:89:75:8E”;
root[“name”] = “sygonix”;
root[“distance”] = (0.89)* pow(id(rssi_sygonix).value/-59,7.7095) + 0.11;
…
1 Like
Flagun
(Marek)
June 16, 2019, 7:17pm
4
could you please send the whole code for ESP?
I can’t make work it out
esp32_ble_tracker:
scan_interval: 10s
id: 'dev_ble'
sensor:
- platform: ble_rssi
mac_address: 84:A4:66:89:75:8E
id: rssi_sygonix
internal: true
on_value:
- mqtt.publish_json:
topic: home_presence/room_1
payload: |-
root["id"] = "84:A4:66:89:75:8E";
root["name"] = "sygonix";
root["distance"] = (0.89)* pow(id(rssi_sygonix).state/-59,7.7095) + 0.11;