Is it possible to have a Thing profile `timestamp-change` for ON only?

Currently I’m using a motion detector updated via MQTT. I have defined the following together with a last motion DateTime item. That tracks when last the value changed.

Switch room_1_motion "Room 1 - Motion" <motion_dynamic> {channel="mqtt:homie300:mosquitto:alarm:room1#open"}
DateTime room_1_motion_last "Room 1 - Last Motion [%1$tT]" <time> {channel="mqtt:homie300:mosquitto:alarm:room1#open" [profile="system:timestamp-change"]}

The room_1_motion_last times when the motion was last switched ON or OFF. This is usually OK but it’s annoying as on initialisation for example the timers get updated to OFF without motion actually being detected but this still updateds the time.
How can I create a profile that only updates the DateTime when the thing is ON?

I know I can do this via a rules, however the profile solution is elegant and easy with many motion detectors.

You know you can use one rule to handle many pairs of Item and timestamp?

In this case, a rule will be the elegant approach, and in fact I don’t think it’s possible at all in a profile. The only alternative profile I can think of would be to use a JS/SCRIPT transform but that will always have to return something so no matter what your DateTime Item’s current state will get wiped out.

To do this in a rule it’s pretty simple.

  • Keep up the current naming convention you show here

  • Put all the motion sensors in a Group

  • Trigger a rule when a member of the Group changes to ON

  • The rule is a one liner. In JS Scripting it would be something like

    items.getItem(event.itemName+‘_last’).postUpdate(time.toZDT().toLocalDateTime().toString());

In Rules DSL

postUpdate(triggeringItemName+'_last', now.toString())

To add more motion sensors just add them to the Group.

Thanks that looks relatively light touch. Have the group already too! Will try and report back!

OK got it working based on @rlkoshak suggestions as follows:

Items:

Group:Switch:OR(ON,OFF) MotionZones "Zones - Open" <motion_dynamic>
Switch room_1_motion "Room 1 - Motion" <motion_dynamic> (MotionZones) {channel="mqtt:homie300:mosquitto:alarm:room1#open"}
DateTime room_1_motion_last "Room 1 - Last Motion [%1$tT]" <time> 
Switch room_2_motion "Room 2 - Motion" <motion_dynamic> (MotionZones) {channel="mqtt:homie300:mosquitto:alarm:room2#open"}
DateTime room_2_motion_last "Room 2 - Last Motion [%1$tT]" <time> 

Rule:

rule "Update _last when alarm zone is open"
when 
    Member of MotionZones changed to ON
then
    postUpdate(triggeringItem.name+"_last", now.toLocalDateTime().toString())
end