Hi, I’ve been asked mulitple times if i can integrate my IoT device with Home Assistant so I’ve decided to give it a go even though i’ve never used Home Assistant before. Hmmm.
I’ve done some research and it seems the add-on architecture is the best way to go for this.
My add on connects to 1-n devices over bluetooth and packages the sensor data received for use with a MQTT broker.
The issue i am having at the moment, is that i need the configuration of the add-on to device the name of 1-n devices parameters (mac_address and name). I’m struggling on getting an “array” or a “list” working in the config.yaml.
I’ve read this post which seems similar to what i’m after but sadly doesnt work optional-array-in-add-on-configuration-option.
Here is what i have so far - it gets as far as installing the add-on but doesn’t let me edit the list of devices without giving me an error message:
---
name: "Monitor of Things BatMon Add-On"
version: "1.1"
slug: "batmon"
description: "An add-on to integrate BatMon BLE sensors with Home Assistant."
arch:
- aarch64
- amd64
- armhf
- armv7
- i386
ports:
8000/tcp: 8000
startup: application
boot: auto
options:
scan_interval: 30
mqtt_broker: "mqtt://homeassistant"
mqtt_username: "your_mqtt_username"
mqtt_password: "your_mqtt_password"
devices:
- mac_address: "XX:XX:XX:XX:XX:01"
name: "Sensor 1"
- mac_address: "XX:XX:XX:XX:XX:02"
name: "Sensor 2"
schema:
scan_interval:
type: int
mqtt_broker:
type: str
mqtt_username:
type: str
mqtt_password:
type: str
devices:
- mac_address: str
name: str
Could any kind folks point me to an example or give me a solution please ?
Thanks in advance, Ringo
On a first glance, your config.yaml looks good. I am personally using String values without " " nowadays, but this should not make any difference.
Please note, that the array does always have to be included in the config of the add-on if you define it like that, an empty array works as well though.
I am using this in my addon (GitHub - brenner-tobias/addon-cloudflared: Connect remotely to your Home Assistant instance without opening any ports using Cloudflared.) where you can have a look at the config.yaml as well as the documentation of the array field.
If you tell me the error you are getting and specify where exactly the error occurs, I am happy to try to help further.
Best
Tobias
1 Like
Yes it was your solution i was looking at thanks. This is the error i get when trying to save the config even without any changes:
The error states a problem with the option “scan_interval:”, not your array.
I suggest to edit the config as yaml (three dots in the right top corner, “Edit in YAML”. You might have an issue with some irrelevant formatting, spaces or something like that.
Feel free to post a screenshot from the raw yaml.
Oh yes !
Its an int in the schema:
ignore the 30.0 bit - it is 30 by default and that has the same issue.n
I think I found the issue, you have to change your schema in the config.yaml:
schema:
scan_interval: int
mqtt_broker: str
mqtt_username: str
mqtt_password: password
devices:
- mac_address: str
name: str
The data type directly follows the variable name, not sure where the “type…” is coming from for your schema. See this documentation: Add-on configuration | Home Assistant Developer Docs
I also suggest to have a look at the more advanced data types there. I already suggested the “password” type, but think that you should also introduce minimums like scan_interval: int(1,60)
and url
for the mqtt broker and a match()
with a proper REGEX for Mac-Addresses.
This can of course also come at a later stage 
Thanks so much!
ChatGPT will to be to blame for the “type” - thats obvs my fault…
1 Like