I have set up the Aqara FP1 presence sensor in zigbee2mqtt, which gives me the following MQTT topics:
Presencesensor1
availability = {"state":"online"}
device_temperature = 21
power_outage_count = 8
motion_sensitivity = high
monitoring_mode = undirected
approach_distance = medium
update-state = idle
update-installed_version = 58
update-latest_version = 58
presence_event = leave
linkquality = 116
action = region_1_unoccupied
presence = false
The one I’m interested in here is the action topic. I am wondering what’s the best way of mapping the actions reported there into openHAB. The topic has quite a number of possible values but these are very clearly structured: the first part signifies the region that triggered the action (in the example above region_1_
stands for region 1 (which is certain area in my kitchen). After that comes the action, which can be “enter”, “leave”, “occupied”, “unoccupied”. You get the idea.
Now I want to create one item in OH for each region and the state of that item would then change based on the actions reported via MQTT. The crux is that I need to map multiple items onto a single MQTT topic and I see multiple ways of doing it but can’t see which one is worth embarking on.
Option 1
Create multiple channels in the FP1 thing, i.e. one for each region. I believe channels can be configured to ignore values in the topic that don’t start with a certain string. The values that are not ignored could then be transformed, either with a RegEx or, give that there are only a few possible values, with a simple map.
Option 2
Create only one channel but link it to multiple items instead (and use transformations similar to option 1). The OH UI seems to be somewhat more user-friendly for this option as it provides different mapping options. At the thing level, I’d have to figure out how to do it).
Option 3
Create one channel and link it to one item, which then triggers a rule that updates the state for each region-item. This option seems easiest for me to implement (I’ve worked a lot with rules but almost not at all with transformations). On the other hand, using rules for this feels like a waste of resources and potentially slower than translations.
Option 0 (not really an option)
I believe there are also ways of doing this already at the level of zigbee2mqtt, which I think also allows to split such a topic into multiple topics. OH would then see a different action topic for each region and the setup would be straight forwards, but I’d prefer not to dig into that and keep my logic in OH.
So, is there any reason to avoid any of these options right away? Is there a best one?