sorry to bump this, but it comes closest to what I am looking for… please help me get a step further?
Having many existing devices, eg via Zwave, to which I want to add several ‘day_start’ sensors, so they appear in the devices overview.
lets take a Zwave device Audio Gym:
this has a device_id
I learned via Tinkerer in Discord, I can ‘fake’ discovery on those, so I can set the discovery topic and tie the following (now standalone) Mqtt sensors to this device:
- unique_id: audio_gym_power_daystart
state_topic: ha_main/sensor/audio_gym/power_daystart
name: Audio Gym power daystart
<<: *power
- unique_id: audio_gym_usage_daystart
state_topic: ha_main/sensor/audio_gym/usage_daystart
name: Audio Gym usage daystart
<<: *energy
these sensors are updated daily (…) via an automation, and I have about 35 of those sets.
- alias: Set daystart sensors
id: set_daystart_sensors
trigger:
platform: time
at: '00:00:01'
action:
service: python_script.record_daystart
I understand I need to automate a topic publication and retain that, so it needs to be done only once.
Tara’s example above creates a full device, but I only need to add these 2 sensors to the existing device.
what am I supposed to publish exactly… and which of the map options should I use: MQTT Sensor - Home Assistant
Ofc, If I need to change those daystart sensors themselves, please let me know, because they have no other dependencies currently.
I also have another option to create those daystart sensors, and that is without a python script , but use this core Ha script:
script:
publish_sensor_daystart_values:
alias: Publish sensor daystart values
sequence:
- variables:
switches: >
{{expand('switch.z_wave_switches',
'switch.dorm_studenten','switch.symfonisk_dining')
|map(attribute='object_id')|list}}
- repeat:
count: >
{{switches|count}}
sequence:
- variables:
oid: >
{{switches[repeat.index - 1]}}
actueel: >
sensor.{{oid}}_actueel
totaal: >
sensor.{{oid}}_totaal
- service: mqtt.publish
data:
topic: >
ha_main/sensor/{{oid}}/power_daystart
payload_template: >
{{states(actueel)}}
qos: 2
retain: true
- service: mqtt.publish
data:
topic: >
ha_main/sensor/{{oid}}/usage_daystart
payload_template: >
{{states(totaal)}}
qos: 2
retain: true
maybe that would make things easier?
the device_registry for this device is:
{
"config_entries": [
"62213aa5a398677a26e1a3354a861183"
],
"connections": [],
"identifiers": [
[
"zwave_js",
"3967834106-71-271:1538:4099"
],
[
"zwave_js",
"3967834106-71"
]
],
"manufacturer": "Fibargroup",
"model": "FGWP102",
"name": "Metered Wall Plug Switch",
"sw_version": "3.2",
"hw_version": null,
"entry_type": null,
"id": "93991b3640262c0fa3a7c9b96342513c",
"via_device_id": null,
"area_id": "gym",
"name_by_user": "Audio Gym",
"disabled_by": null,
"configuration_url": null
}
seems the topic/payload should be:
device: ha_main/sensor/audio_gym
payload: >
{"identifiers": ["93991b3640262c0fa3a7c9b96342513c","Audio Gym"],
"name":"Metered Wall Plug Switch",
"manufacturer": "Fibargroup",
"model": "FGWP102"}
in topic publish window:
if I do that, MQTT sees this:
and there is no tie in at all…
I can add the device_id to the key in the entity_registry of these sensors manually, immediate effect:
now how to do that from within the UI, or backend automation…