but doesn’t work.
Where is my mistake?
I already found a workaround using 2 rules that set the item on or off according to thing change…
But i want to bettern learn how to create objects to have clean code.
Not to be too blunt, but you’ve guessed at how things work and invented syntax that is not supported. The “availabilityTopic” isn’t a Channel. You can’t link it to an Item. That part of the Thing config will cause the Thing to go OFFLINE if “offline” is published to that topic. It controls the Thing’s state and has nothing to do with Items.
You could create a switch Channel to subscribe to that topic and link that to an Item.
You can use rules. There is nothing “unclean” about using rules. You could probably consolidate it down to one rule. And you don’t even need to write the this rule. There’s a Thing Status rule template you can install and use. OH 3.4.2 version, OH 4.0 version.
You can forego the Item entirely. As an admin user you can see the status of the Thing in MainUI. In your rules you can get the status of the Thing using the thingStatusInfo Action. The status of the Thing is not something the end users of your home automation are likely to care about so there should be no reason to expose it to them as an Item.