I’m presuming the OP is wanting ot publish every, or at least, most sensors. Is there a way of grouping a bunch of sensors and if they’re a member of that group they’re all published?
Not really, I create a lot of my sensors by the MQTT platform. Some data sources are slightly easier to get using the RESTful sensor (especially if in XML format), but I was looking to publish (some of) that data.
Yes I do that extensively already.
I was aware I could publish by polling HA with NR, I just wondered if there was an easier way.
On a related issue, can you get a notification when a service is run? I’m using the speedtestdotnet component and I want to publish the result. I don’t want to poll the sensor, I want to know when it has run then publish the latest value.
Not really Sort of. If you have a group of sensors called group.all_sensors and do this:
trigger:
platform: state
entity_id: group.all_sensors
all it will accomplish is to trigger when the group’s state changes; you won’t know which member of the group changed its state. You would have to blindly publish the states of all group members regardless if the member had changed its state or not. That’s not a recommended design pattern.
EDIT
There’s no guarantee that bad practice will even work properly. Here’s a simple failure scenario:
You have a group of binary_sensors, they are all off, so the group’s state is also off.
One of the binary_sensors turns on so now the group’s state is on.
The group’s state-change causes the ‘bad practice’ Template Sensor to publish the state of the group’s members (so far, so good).
Another binary_sensor in the group turns on.
The group’s state is already on so there’s no state-change.
The Template Sensor doesn’t publish anything and there’s the flaw.
However all of this amounts to creating an automation that’s triggered by an event, which is effectively equivalent to an automation that is triggered by a sensor’s state-change (namely the speedtestdotnet sensor you already have).
Effectively equivalent, meaning in both cases you need to use an automation.
Not sure why you would need to publish a value that hasn’t changed since the last time it was published but, yes, triggering based on event detection of the speedtest service will allow you to do that.
If its for speedtestdotnet, you may wish to explore at MQTT Eventstream.
FWIW, if there’s only one sensor, or just one service, that needs to be published then it seems to me that firing up an entire new integration (either MQTT Statestream or Eventstream) is overkill. A single automation will get the job done equally well.
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: