Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for messaging via mqtt #17148

Open
normanmaurer opened this issue Nov 9, 2024 · 16 comments · May be fixed by #17211
Open

Add support for messaging via mqtt #17148

normanmaurer opened this issue Nov 9, 2024 · 16 comments · May be fixed by #17211
Assignees
Labels
enhancement New feature or request

Comments

@normanmaurer
Copy link

At the moment there are various supported ways how to use messaging. It would be nice if you could add mqtt as well. This would allow to easy integrate with other software that could just subscribe to a topic.

@andig
Copy link
Member

andig commented Nov 9, 2024

What kind of "messaging"?

@andig andig added the question Rather clarification than issue label Nov 9, 2024
@normanmaurer
Copy link
Author

normanmaurer commented Nov 9, 2024

This one https://docs.evcc.io/docs/reference/configuration/messaging

So I think it is not really messaging but services that is used by messaging

@andig
Copy link
Member

andig commented Nov 9, 2024

I see. That would mean adding a custom push device. Not a priority, but happy to take a PR. Doing so it would also be nice to remove the script push device- it can already be implemented using the script plugin.

/cc @GrimmiMeloni in case you're interested

@andig andig added enhancement New feature or request and removed question Rather clarification than issue labels Nov 9, 2024
@normanmaurer
Copy link
Author

Yeah for now I just use the script stuff with mosquito_pub

@GrimmiMeloni GrimmiMeloni self-assigned this Nov 10, 2024
@GrimmiMeloni
Copy link
Collaborator

Yeah, about time for me to contribute something again. ;)

@normanmaurer what would an MVP look like? Does simply configuring a broker + a topic to publish to suffice?

@normanmaurer
Copy link
Author

@GrimmiMeloni yes 🎉

@andig
Copy link
Member

andig commented Nov 10, 2024

Spannend ist noch wie wir mit title und msg umgehen. Vllt. Lassen wir bei den custom Integrationen einfach den title weg?

@normanmaurer
Copy link
Author

Or we could also use json for the payload

@andig
Copy link
Member

andig commented Nov 10, 2024

Like it. Could be an encoding option on the custom messenger.

@GrimmiMeloni
Copy link
Collaborator

I am wondering why we are talking custom here? I was planning to just add an mqtt flavor to the list of supported messaging services (shoutr, telegram, ....)

@andig
Copy link
Member

andig commented Nov 11, 2024

I just thought we have custom everywhere and script already is a custom integration. Why not make it fully flexible before the next user wants http?

@GrimmiMeloni
Copy link
Collaborator

OK. But if we already have a custom solution via script, then what is actually missing here? Sorry for being "stupid", but I still don't understand the actual ask. Can you maybe show an example of the configuration you expect, or some other fragment that explains what the difference between script and custom would be?

@andig andig linked a pull request Nov 12, 2024 that will close this issue
@rhuss
Copy link
Contributor

rhuss commented Nov 15, 2024

Sorry, just have seen this issue. By accident, I've implemented a type 'mqtt' in #17278 which is just reusing the existing MQTT client. This simple addition is also documented in evcc-io/docs#670

@rhuss
Copy link
Contributor

rhuss commented Nov 15, 2024

Just read through this issue, my thoughts here:

  • For MQTT the "title" can IMO be mostly ignored. For JSON payloads I just added the title with a field "title" within this payload.
  • I wonder whether multiple MQTT endpoints are required or if the single MQTT endpoint that is also used by plugins is good enough. It shouldn't be hard to either add MQTT config to the service configuration or allow multiple MQTT Broker instances (that then would be configured in a list)

@rhuss
Copy link
Contributor

rhuss commented Nov 15, 2024

Here is an example, how the title is treated in #17278 with JSON (otherwise its ignored):

# MQTT Broker Configuration
mqtt:
  broker: broker.mqtt:1883
  user: evcc
  password: s3cr3t

# Send lifecycle events via MQTT
messaging:
  events: 
    connect:
      # Title is added later to JSON. Just omit it if not needed
      title: "Car connected"
      # Use template to create JSON payload
      msg: '{"car": "${vehicleTitle}", "mode": "${mode}", "event": "connect"}'
  services:
  - type: mqtt
    topic: 'evcc/events'

This will result in payloads that look like

{
  "car": "Ioniq 6", 
  "mode": "PV",
  "title": "Car connected"
  "event": "connect"
}

@andig
Copy link
Member

andig commented Nov 15, 2024

Is there anything in the suggested PR that prevents this pattern?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants