Hello and thank you for your time, I am using a esp32 and the device id is automaticity set to esp32_66FC10 which is the last six characters of the MAC address.
I would like to be able to set this as part of some custom fields in mos.yml.
Something like - [“device.batterytopic”, “/home/doorsensor_66FC10”]
I also would like to know how to do it in mos.yml.
What I did in this example was using Cfg.get() and Cfg.set() in JS to write them on first boot:
let client_id = Cfg.get('device.id');
let thing_id = tolowercase(client_id.slice(client_id.length-6, client_id.length));
let base_topic = 'homie/ohsb' + thing_id;
let state_topic = base_topic + '/$state';
[...]
// homie-required last will
if(Cfg.get('mqtt.will_topic') !== state_topic) {
Cfg.set({mqtt: {will_topic: state_topic}});
Cfg.set({mqtt: {will_message: 'lost'}});
Cfg.set({mqtt: {client_id: client_id}});
Log.print(Log.INFO, 'MQTT last will has been updated');
};