Mistral AI API - Custom Integration

Hello everybody,

I just created my first custom integration. I never developed an integration for home assistant before so things might be rough, but they work and I think people could benefit from it.

So, this is the Mistral AI API for Home Assistant.

Mistral AI is a (currently) free european (french) AI. It features several fine-tuned models for text generation, image generation, code generation and more.

The integration allows you to send prompts to either the mistral ai itself or to one of the agents (which you define on their site).

All you need is to sign-up with them and get an api-key (all free).
The integration then offers a new service calles mistral_ai_api.send_prompt

You can input the prompt, define the model you wish to use (or decide to use an agent by using an agent-id) and define a custom identifier.

Once the response is available an event will be thrown which includes the reponse and the identifier of that prompt.

I used this to feed the AI my sensors for temperature and humidity along with temperature and humidity outside and then got recommendations on if I should ventilate.

However, as I didn’t want to repeat this automation all the time I then let the ai generate a template for me with my data which I then pasted into HA to have a template sensor which now lets me know if I should ventilate.

There’s lots you COULD do with this. If you decide to use the coding model you could let the ai create jinja + markdown to be used directly within the dashboard.

I am currently trying to get this to be available on HACS, but since this is my first time doing all of this things might take a while.

If you got any suggestions I’d be happy to hear them.

Here is an example script:

action: mistral_ai_api.send_prompt
metadata: {}
data:
  identifier: Rückgabe
  model: mistral-large-latest
  prompt: >-
    I'm thinking bout wether I should ventilate my home. The outside temperature
    is     {{state_attr('weather.forecast_home','temperature')}} degree and the
    outside humdity is      {{state_attr('weather.forecast_home','humidity')}}%.
    The avarage temperature of all my rooms is            
    {{states('sensor.durchschn_temperatur_in_der_wohnung')}} degree and the
    avarage humidity of all my rooms is         
    {{states('sensor.durchschn_feuchtigkeit_in_der_wohnung')}}%. Should I
    ventilate? Explain your reasoning.

And here is the answer

To determine whether you should ventilate your home, it’s important to consider the effects of temperature and humidity on indoor air quality and comfort. Here’s a breakdown of your situation:

  • Outside Conditions:
    • Temperature: 2.3°C
    • Humidity: 89%
  • Inside Conditions:
    • Temperature: 18.5°C
    • Humidity: 57%

Key Considerations:

  1. Temperature Difference:
  • The outside temperature is significantly lower than the inside temperature. Ventilating by opening windows could lead to a drop in indoor temperature, making the environment colder.
  1. Humidity Levels:
  • The outside humidity is much higher than the inside humidity. Introducing this high humidity into your home could increase the indoor humidity levels, which might lead to discomfort and potential issues like condensation and mold growth.
  1. Indoor Air Quality:
  • Ventilation helps to reduce indoor pollutants, odors, and carbon dioxide levels, improving overall air quality. However, it should be balanced with maintaining comfortable temperature and humidity levels.

Recommendations:

Given the significant difference in temperature and humidity, it might not be the best time to ventilate your home by simply opening windows. Here are some alternative suggestions:

  1. Mechanical Ventilation:
  • If your home has a mechanical ventilation system (e.g., heat recovery ventilator), use it. These systems can exchange indoor and outdoor air while maintaining temperature and humidity levels.
  1. Short Bursts of Ventilation:
  • Open windows for short periods (e.g., 5-10 minutes) to allow for some air exchange without drastically affecting the indoor temperature and humidity.
  1. Monitor Indoor Air Quality:
  • Use indoor air quality monitors to check levels of pollutants, carbon dioxide, and humidity. This can help you decide when ventilation is necessary.
  1. Use Dehumidifiers:
  • If you decide to ventilate and notice an increase in indoor humidity, consider using a dehumidifier to maintain comfortable levels.

Conclusion:

Based on the current conditions, it might be better to avoid prolonged ventilation by opening windows. Instead, consider using mechanical ventilation or short bursts of ventilation to maintain indoor air quality without compromising comfort.

The answer right now is fetched from an event and then added as a permanent notification in home assitant. Here is how I do this:

alias: "[Mistral AI] React on mistral ai response"
description: ""
triggers:
  - trigger: event
    event_type: mistral_ai_response
conditions: []
actions:
  - action: persistent_notification.create
    metadata: {}
    data:
      message: "{{trigger.event.data.response}}"
mode: single
2 Likes

It’s a great job !

Do you think it would be possible either to add an option on the official openai_conversation integration to switch hosts and use Mistral’s AI models directly for Assist or either to make this integration compatible with Assist api if it’s not ?

I have no idea how exactly communication for assist is done… so, dunno. I am really new to developing HA stuff

Awesome - I just started to experiment with Mistral and was wondering if I can use my local voice assistant with it when I bumped into your integration.

There is guidance on the LLM API integration into assist - but must say this is completely new to me as well…

Home Assistant API for Large Language Models | Home Assistant Developer Docs

That looks and sounds really cool. But for now thats far too advanced for me. I still struggle with the basics in developing for home assistant…