WTH can't I manually create a device from entities?

Why can’t we manually create a device, either via YAML, UI, or preferably both? Also, why can’t we edit existing devices to add entities to them?

As an example, I have some devices that connect via MQTT, without discovery. They’re a couple of sensors/binary_sensors. I’ve manually created a couple of devices by publishing some MQTT discovery messages for them instead of configuring them via YAML. In the MQTT sensor integration documentation, it even has a section for device, but even if you fill everything here out, and provide a unique_id, it’s ignored unless all being provided via MQTT discovery.

Why can’t I fill out the device section in a YAML file and create a device? I can publish the exact same info as a JSON payload to the discovery topic and create a device, I should be able to do this via YAML. Also, if I were able to do this via YAML, I should also be able to hot-reload the config and create the new device without a restart, since I can do this via MQTT discovery without a reboot.

Another extremely useful thing would be to be able lump template sensors in with the device they’re created from, or make a new device out of them. If I create a template sensor from a device, it becomes a stand-alone entity, not linked to that device. We really need a way to create and edit devices.

If this is implemented, one thing that would be very useful with this would be the ability to flag one of the entities as being the one that reports the battery level so it shows as the battery indicator on the devices tab.

This is handled by that entity being of device_class: battery, there’s no need to have any sort of ‘tag’ added, as that is precisely what device_class does.

2 Likes

I wanted to post EXACTLY the same thing.
So i support this WTH 100%.

I have multiple devices using MQTT and I still don’t understand why device, uniq_id etc … are not used without discovery.

For multiple reasons I don’t use discovery. This would be really usefull for entity grouping, battery management, device poisitionning in rooms etc …

1 Like

I also agree - here is my predicament - has to do with not being able to manually create a device, and not being able to use discovery either.

I am using Tuya switch/smartplug devices with Tasmota. I have had no problem at all with discovery on devices that I should use discovery with.

However, I have followed the advice that for three-way switches, one should NOT use discovery because it would show both the output state and an internal state. I have manually added the three-way switches to configuration.yaml, and they work perfectly. I can turn them on and off with the HA controls, or manually, and the status shown on the display is correct.

So what is the problem, you ask. Here is the problem. The switches I created in the configuration.yaml file are entities, and they are switches, but they are not devices. Of course, you say, you cannot create devices except through integrations. I don’t agree that this is a good thing, but it is what it is. And, there is no ability to set the area for these non-devices, as well.

I need to create automations on these non-device switches, but I can’t do that either through the gui because it only works on devices.

So, I saw a post about publishing to the mqtt discovery service to manually “discover” a switch, but I cannot find a working example of this anywhere.

Has anyone got automations working on a three way switch through mqtt/tasmota? How did you do it?

That is definitely not true.

image

Were you able to figure out a workaround? I have the same issue

HA! (as in laughter). Still seems there isn’t a straightforward way to do this. I have an old Photon publishing data to mqtt just fine but there is no discovery component to it even though I can sub to from HA and see the data getting published.

MQTT discovery supports creating a device, so make an automation that does it.

I have devices that broadcast MQTT that don’t have discovery options. I can subscribe to them without an issue in OpenHAB. Something that HA lacks it being able to build out an MQTT device manually. I had created one in configuration.yaml and it worked until an update broke it. I’m glad it wasn’t my full MQTT setup that I rely on for other rules to trigger. For now I’m running HA and OH both.

That’s what I’m saying. You can build discovery with an automation that does what you want.

Is there a guide to do it via Automation? I see the MQTT and topic options. I’ve created one string but it isn’t showing a value but I can sub to it no problem in Integrations/MQTT.

1 Like

One of my scripts as an example:

  scriptmyautodiscovery:
    sequence:
#      - service: mqtt.publish
#        data:
#          retain: true
#          topic: 
#          payload: 
      - service: mqtt.publish
        data:
          retain: true
          topic: homeassistant/binary_sensor/garagedoor/config
          payload: '{"name": "garagedoor", "device_class": "garage_door", "state_topic": "sensor/garagedoor", "unique_id": "garagedoor", "off_delay": 30, "device": {"identifiers": ["rfbridge_564886"],"name": "garagedoor", "model": "Digoo door sensor", "manufacturer": "Digoo"}}'
      - service: mqtt.publish
        data:
          retain: true
          topic: homeassistant/binary_sensor/sensortvboven/config
          payload: '{"name": "sensorTVboven", "device_class": "plug", "state_topic": "sensor/tvboven", "unique_id": "sensortvboven", "device": {"identifiers": ["sensorTVboven"],"name": "sensorTVboven", "model": "Action Switches", "manufacturer": "Action"}}'
      - service: mqtt.publish
        data:
          retain: true
          topic: homeassistant/binary_sensor/sensorproximusboven/config
          payload: '{"name": "sensorProximusboven", "device_class": "plug", "state_topic": "sensor/proximusboven", "unique_id": "sensorproximusboven", "device": {"identifiers": ["sensorproximusboven"],"name": "sensorProximusboven", "model": "Action Switches", "manufacturer": "Action"}}'
      - service: mqtt.publish
        data:
          retain: true
          topic: homeassistant/binary_sensor/sensorfanboven/config
          payload: '{"name": "sensorfanboven", "device_class": "plug", "state_topic": "sensor/fanboven", "unique_id": "sensorfanboven", "device": {"identifiers": ["sensorfanboven"],"name": "sensorfanboven", "model": "Action Switches", "manufacturer": "Action"}}'
      - service: mqtt.publish
        data:
          retain: true
          topic: homeassistant/binary_sensor/sensorrflinkboven/config
          payload: '{"name": "sensorrflinkboven", "device_class": "plug", "state_topic": "sensor/rflinkboven", "unique_id": "sensorrflinkboven", "device": {"identifiers": ["sensorrflinkboven"],"name": "sensorrflinkboven", "model": "Action Switches", "manufacturer": "Action"}}'
      - service: mqtt.publish
        data:
          retain: true
          topic: homeassistant/binary_sensor/sensorpirtrap/config
          payload: '{"name": "sensorPirtrap", "device_class": "motion", "state_topic": "sensor/pirboven", "unique_id": "sensorpirtrap", "off_delay": 90, "device": {"identifiers": ["sensorpirtrap"],"name": "sensorpirtrap", "model": "Digoo Pir", "manufacturer": "Digoo"}}'
      - service: mqtt.publish
        data:
          retain: true
          topic: homeassistant/binary_sensor/sensorvoordeur/config
          payload: '{"name": "voordeur", "device_class": "door", "state_topic": "sensor/voordeur", "unique_id": "voordeur", "device": {"identifiers": ["voordeur"],"name": "voordeur", "model": "Digoo door sensor", "manufacturer": "Digoo"}}'
      - service: mqtt.publish
        data:
          retain: true
          topic: homeassistant/sensor/xiron_3201/temperature/config
          payload: '{"unit_of_measurement":"°C","device_class":"temperature","value_template":"{{ value_json.TEMP }}","state_class": "measurement","state_topic":"rflink/Xiron-3201","name":"eetkamer_temperature","unique_id":"eetkamer_temperature","device":{"identifiers":["xiron_3201"],"name":"xiron_3201","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain: true
          topic: homeassistant/sensor/xiron_3201/humidity/config
          payload: '{"unit_of_measurement":"%","device_class":"humidity","value_template":"{{ value_json.HUM }}","state_class": "measurement","state_topic":"rflink/Xiron-3201","name":"eetkamer_humidity","unique_id":"eetkamer_humidity","device":{"identifiers":["xiron_3201"],"name":"xiron_3201","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_4503/temperature/config
          payload: '{"unit_of_measurement":"°C","device_class":"temperature","value_template":"{{ value_json.TEMP }}","state_class": "measurement","state_topic":"rflink/Xiron-4503","name":"boven_temperature","unique_id":"Xiron_4503_temp","device":{"identifiers":["xiron_4503"],"name":"xiron_4503","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_4503/humidity/config
          payload: '{"unit_of_measurement":"%","device_class":"humidity","value_template":"{{ value_json.HUM }}","state_class": "measurement","state_topic":"rflink/Xiron-4503","name":"boven_humidity","unique_id":"boven_humidity","device":{"identifiers":["xiron_4503"],"name":"xiron_4503","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_2f02/temperature/config
          payload: '{"unit_of_measurement":"°C","device_class":"temperature","value_template":"{{ value_json.TEMP }}","state_class": "measurement","state_topic":"rflink/Xiron-2F02","name":"zitkamer_temperature","unique_id":"Xiron_2f02_temp","device":{"identifiers":["xiron_2f02"],"name":"xiron_2f02","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_2f02/humidity/config
          payload: '{"unit_of_measurement":"%","device_class":"humidity","value_template":"{{ value_json.HUM }}","state_class": "measurement","state_topic":"rflink/Xiron-2F02","name":"zitkamer_humidity","unique_id":"Xiron_2f02_humidity","device":{"identifiers":["xiron_2f02"],"name":"xiron_2f02","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_4e01/temperature/config
          payload: '{"unit_of_measurement":"°C","device_class":"temperature","value_template":"{{ value_json.TEMP }}","state_class": "measurement","state_topic":"rflink/Xiron-4E01","name":"outside_temperature","unique_id":"Xiron_2e01_temp","device":{"identifiers":["xiron_4e01"],"name":"xiron_4e01","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_4e01/humidity/config
          payload: '{"unit_of_measurement":"%","device_class":"humidity","value_template":"{{ value_json.HUM }}","state_class": "measurement","state_topic":"rflink/Xiron-4E01","name":"outside_humidity","unique_id":"Xiron_4e01_humidity","device":{"identifiers":["xiron_4e01"],"name":"xiron_4e01","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_2202/temperature/config
          payload: '{"unit_of_measurement":"°C","device_class":"temperature","value_template":"{{ ((value_json.TEMP | float) + 0.7)|round(2) }}","state_class": "measurement","state_topic":"rflink/Xiron-2202","name":"garage_temperature","unique_id":"Xiron_2202_temp","device":{"identifiers":["xiron_2202"],"name":"xiron_2202","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_2202/humidity/config
          payload: '{"unit_of_measurement":"%","device_class":"humidity","value_template":"{{ value_json.HUM }}","state_class": "measurement","state_topic":"rflink/Xiron-2202","name":"garage_humidity","unique_id":"Xiron_2202_humidity","device":{"identifiers":["xiron_2202"],"name":"xiron_2202","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_1701/temperature/config
          payload: '{"unit_of_measurement":"°C","device_class":"temperature","value_template":"{{ ((value_json.TEMP | float) - 0.4)|round(2) }}","state_class": "measurement","state_topic":"rflink/Xiron-1701","name":"badkamer_temperature","unique_id":"Xiron_1701_temp","device":{"identifiers":["xiron_1701"],"name":"xiron_1701","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_1701/humidity/config
          payload: '{"unit_of_measurement":"%","device_class":"humidity","value_template":"{{ value_json.HUM }}","state_class": "measurement","state_topic":"rflink/Xiron-1701","name":"badkamer_humidity","unique_id":"Xiron_1701_humidity","device":{"identifiers":["xiron_1701"],"name":"xiron_1701","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_4B01/temperature/config
          payload: '{"unit_of_measurement":"°C","device_class":"temperature","value_template":"{{ ((value_json.TEMP | float) - 0.4)|round(2) }}","state_class": "measurement","state_topic":"rflink/Xiron-4B01","name":"kamerdestiny_temperature","unique_id":"Xiron_4B01_temp","device":{"identifiers":["xiron_4B01"],"name":"xiron_4B01","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_4B01/humidity/config
          payload: '{"unit_of_measurement":"%","device_class":"humidity","value_template":"{{ value_json.HUM }}","state_class": "measurement","state_topic":"rflink/Xiron-4B01","name":"kamerdestiny_humidity","unique_id":"Xiron_4B01_humidity","device":{"identifiers":["xiron_4B01"],"name":"xiron_4B01","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_3002/temperature/config
          payload: '{"unit_of_measurement":"°C","device_class":"temperature","value_template":"{{ value_json.TEMP }}","state_class": "measurement","state_topic":"rflink/Xiron-3002","name":"bovengang_temperature","unique_id":"Xiron_3002_temp","device":{"identifiers":["xiron_3002"],"name":"xiron_3002","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_3002/humidity/config
          payload: '{"unit_of_measurement":"%","device_class":"humidity","value_template":"{{ value_json.HUM }}","state_class": "measurement","state_topic":"rflink/Xiron-3002","name":"bovengang_humidity","unique_id":"Xiron_3002_humidity","device":{"identifiers":["xiron_3002"],"name":"xiron_3002","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_6402/temperature/config
          payload: '{"unit_of_measurement":"°C","device_class":"temperature","value_template":"{{ value_json.TEMP }}","state_class": "measurement","state_topic":"rflink/Xiron-6402","name":"kleineslaapkamer_temperature","unique_id":"Xiron_6402_temp","device":{"identifiers":["xiron_6402"],"name":"xiron_6402","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/sensor/xiron_6402/humidity/config
          payload: '{"unit_of_measurement":"%","device_class":"humidity","value_template":"{{ value_json.HUM }}","state_class": "measurement","state_topic":"rflink/Xiron-6402","name":"kleineslaapkamer_humidity","unique_id":"Xiron_6402_humidity","device":{"identifiers":["xiron_6402"],"name":"xiron_6402","model":"Digoo temp & humidity sensor","manufacturer":"Digoo"}}'
      - service: mqtt.publish
        data:
          retain : true
          topic: homeassistant/binary_sensor/waterkraan/config
          payload: '{"name": "waterkraan", "device_class": "moisture", "state_topic": "sensor/waterkraan", "unique_id": "waterkraan_binary_sensor", "device": {"identifiers":["20067C"]}}'
          
2 Likes

Because that is user friendly. We just need simple templates. I can sub to garage/temperature but have to jump through hoops to see it in HA. And I had done it configuration.yaml until it broke on an update. There’s a lot to be said for K.I.S.S.