123
(Taras)
March 10, 2020, 7:25pm
21
As described in one of my earlier posts .
Try this experiment:
Go to Developer Tools > Events
Scroll down to Listen to an event
Enter call_service
in Event to subscribe to
Click Start Listening
In another browser tab (or window) open the Lovelace UI and turn on a light.
Return to the browser pane containing Developer tools > Events and you’ll see the call_service event details for the service that turned on the light (i.e. light.turn_on
).
For example, I have a patio light and here’s the event reported when I turned on the light:
Event 0 fired 3:10 PM:
{
"event_type": "call_service",
"data": {
"domain": "light",
"service": "turn_on",
"service_data": {
"entity_id": "light.patio"
}
},
"origin": "LOCAL",
"time_fired": "2020-03-10T19:10:16.090753+00:00",
"context": {
"id": "redacted",
"parent_id": null,
"user_id": "redacted"
}
}
I can use that information to create an automation with an Event Trigger that fires only for that specific service call. Something like this:
trigger:
platform: event
event_type: call_service
event_data:
domain: light
service: turn_on
For your application, I imagine it would look like this:
trigger:
platform: event
event_type: call_service
event_data:
domain: speedtestdotnet
service: speedtest
1 Like
baz123
(Brian)
March 11, 2020, 9:51am
22
@123 , Thanks for the help.
The final solution is this (from the automation UI);
Trigger
platform: event
event_type: state_changed
event_data:
domain: speedtestdotnet
attributes: last_updated
entity_id: sensor.speedtest_download
Action
data_template:
payload_template: '{{ states.sensor.speedtest_download.state }}'
topic: emon/speedtest
service: mqtt.publish
3 Likes
123
(Taras)
March 11, 2020, 12:10pm
23
I think you missed the spirit of what constitutes the “Solution”.
123
(Taras)
March 11, 2020, 12:18pm
25
The answer will reveal itself to you eventually.
paki111
(Patryk)
April 23, 2020, 11:39am
26
Thank’s. This is the easiest way I found
1 Like
123
(Taras)
May 21, 2021, 1:06pm
28
You just posted in a thread that had been dead for over a year and I have no idea what you’re talking about.
meeDamian
(Damian Mee)
June 29, 2021, 5:04am
29
Thank you @baz123 for posting your solution here
2 Likes
Tamadite
(jesuschal)
July 6, 2021, 7:42pm
30
Just for the record, another example that gets triggered by updates on sensor:
- alias: Publish on sensor update
trigger:
platform: state
entity_id: sensor.0x123456000123456d_temperature
action:
- service: mqtt.publish
data_template:
payload_template: "{{ states('sensor.0x123456000123456d_temperature') }}"
topic: whatever/topic/you/want
2 Likes
123
(Taras)
July 6, 2021, 7:53pm
31
Tamadite:
Just for the record,
Just for the record, there’s no need to use payload_template
. Even the example I posted over a year ago simply uses payload
with a template.
A year later and now it’s no longer required to use data_template
either. It was deprecated in favor of simply using data
(several versions ago).
Tamadite
(jesuschal)
July 9, 2021, 7:46pm
32
On core-2021.3.3 replacing payload_template
by payload
gives an error.
Same applies for data_template
vs data
.
123
(Taras)
July 9, 2021, 8:05pm
33
Upgrade Home Assistant.
2021.3 lacks many enhancements and any recent discussion on this forum is focused on the features of recent versions, not old ones. 2021.3 is now four versions ago.
In fact, the official documentation always represents features found in the latest version of Home Assistant. Anyone using an old version may experience difficulties with the documentation because it will explain something that may not exist, or work differently, in their old version.
bwired
(bwired)
January 1, 2023, 3:36pm
34
I have this working great for sending my cars entity’s to mqtt also
But 1 of the entity’s is having extra attributes, How do I get the tribute on the mqtt as well?
mqtt_statestream:
base_topic: bmw
include:
entities:
- sensor.i4_edrive40_remaining_battery_percent
- sensor.i4_edrive40_mileage
- binary_sensor.i4_edrive40_charging_status
- device_tracker.i4_edrive40
- sensor.i4_edrive40_charging_end_time
- sensor.i4_edrive40_remaining_range_total
- sensor.i4_edrive40_remaining_range_electric
- binary_sensor.i4_edrive40_lids
- sensor.i4_edrive40_charging_status
- binary_sensor.i4_edrive40_connection_status
for example the entity device_tracker.i4_edrive40 has attributes like
Source type: gps
Latitude: 53.73
Longitude: 3.3
GPS accuracy: 0
Direction: 165
How do I get these attributes also on mqtt
i have tried
device_tracker.i4_edrive40.Latitude for example, but this does not work
any tips?
Please help me to understand mqtt a little better. I have this enphase sensor for solar production.
sensor.envoy_122248025029_today_s_energy_production