Mqtt to homeassistant

I struggling to understand how to control a home assistant entity trough mqttt. I have a entity with n number as a set point that I would like to change through mqtt. so when the number changes trough mqtt that new value is commanded to the enitity. What would be the best way to do this.

How to you want to set the value?

From an input number in your dashboard or will it always be the same value?

What is the topic to publish the number to?

Basically I want to subscribe to a topic that has a number or a setpoint then have that number be the new value for the water heater entity setpoint. That number would be different witch is where I’m struggling. I know how to set up a automation to listen to a mqtt topic but that’s just a switch not something that’s going to be different. I have the mqtt statestream setup and I can see everything I want in mqtt explorer I just have no way to actually control it

You are still not being clear. How do you want to control the set point?

If you want to do it from your HA dashboard do this:

  1. Remove mqtt statestream. You don’t need that.

  2. Create an input number helper, Settings → Devices and Services → Helpers, or do it in YAML

input_number:
  my_setpoint:
    name: My Setpoint
    unit_of_measurement: "°C"
    min: -20
    max: 35
    step: 1
    mode: slider # or "box" if you prefer to enter the number directly

Use a meaningful name, unit, min and max. You can change to mode to be a slider or an input box, depending on what you want.

  1. Create an automation to publish to the topic whenever the input number changes:
trigger:
  - platform: state
    entity_id: input_number.my_setpoint
    not_to:
      - unknown
      - unavailable
action:
 - service: mqtt.publish
   data:
    topic: your/mqtt//number/topic/here
    payload_template: "{{ trigger.to_state.state }}"
  1. Add the input number to an entities card in your dashboard. Change this input and it will be published to your topic.

I suggest you simply model the water heater using this:

Then you can use temperature_state_topic to control the water heater’s target temperature.


EDIT

If your water heater isn’t controllable via MQTT then that integration won’t be useful.

I don’t want to create a new topic or entity the entity I want to control has already been set up. Its a Rheem econet water heater “water_heater.electric_water_heater”
What I’m trying to do is control its setpoint from openhab. I can subscribe to all of it’s states but I don’t know how to control it with mqtt. I just want to have the water heater setpoint equal the mqtt command topic

Unfortunately it is not

Make an automation with an MQTT Trigger that uses the received payload to set the water heater’s (water_heater.electric_water_heater) target temperature with water_heater.set_temperature.

The received payload can be referenced using trigger.payload

Finally we get the details.

Though it is still not exactly clear.

If you mean you want to control this set point in openhab then you should be posting this on the openhab forum.

If you mean control a device in openhab from home assistant via mqtt then follow 123’s advice above.

Well you still haven’t told us:

Honestly it’s like pulling teeth trying to get the required information from you. And I give up. Good luck.

1 Like