-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compatibility with ESPHome #67
Comments
esphome/esphome#719 gives some clues, here it would be for HTTP telemetry, but it can surely be applied to MQTT as well: - http_request.post:
url: https://api.telegram.org/bot<BOT_ID>:<BOT_SECRET>/sendMessage
headers:
Content-Type: application/json
X-Custom-Header: !lambda |-
return "hValue";
json:
chat_id: <CHAT_ID>
disable_web_page_preview: 1
text: !lambda |-
char str[20];
time_t currTime = id(sntp_time).now().timestamp;
strftime(str, sizeof(str), "%Y-%m-%d %H:%M:%S", localtime(&currTime));
return (std::string) "Current time is " + str; It looks like this example uses Templates (Lambdas):
However, using the non-lambda approach like outlined in the first comment, could this work as well in order to bring the current value of the SNTP Time Source into the outbound MQTT payload, just using - mqtt.publish_json:
topic: amazonas/ecuador/cuyabeno/node-01/data.json
payload: |-
root["key"] = id(my_sensor).state;
root["time"] = id(sntp_time).now().timestamp;
root["greeting"] = "Hello World"; [1] Is there actually a difference, or is |
We just heard back from the workbench that this snippet works well: time:
- platform: sntp
id: sntp_time
mqtt:
broker: foobar
on_message:
- topic: esp32/bme280
payload: "status"
qos: 0
then:
- mqtt.publish_json:
topic: workbench/testdrive/area-42/evb-ea-ind-02/data.json
payload: |-
root["time"] = id(sntp_time).now().timestamp;
root["bme280_temp"] = id(bme280_temperature).state;
root["bme280_humidity"] = id(bme280_humidity).state;
root["bme280_pressure"] = id(bme280_pressure).state; Thanks for sharing! |
As a newcomer to ESPHome, I am interested in some more details: I see from the configuration snippet above that on_message:
- topic: esp32/bme280 Does that mean that the outbound message is only submitted when an inbound message to the MQTT topic Would there also be a way to make the ESPHome firmware publish those measurements periodically? |
Finding the relevant information was easy. The
time:
- platform: sntp
on_time:
# Cron syntax, trigger every 5 minutes
- cron: '* /5 * * * *'
then:
- switch.toggle: my_switch Please note there is also the
# Example configuration entry
interval:
- interval: 1min
then:
- switch.toggle: relay_1 Kudos again to @OttoWinter for conceiving this excellent component framework! |
Now, it would be sweet to get a full working example how to bring both details (sensor reading & MQTT publishing vs. periodic actions) together, either based on the Maybe those would work already? I will be happy to receive feedback. Using
|
Hi there,
friends of Kotori recently started playing with the excellent ESPHome by @OttoWinter and contributors (cheers!). It would be sweet to add a corresponding page to the documentation which outlines best practices how both software components can be made work together, based on ESPHome's mqtt.publish_json Action.
It looks pretty straight-forward, yet we will have to figure out how to embed the timestamp (Time) into the MQTT payload.
With kind regards,
Andreas.
The text was updated successfully, but these errors were encountered: