Issue is, whenever i trigger this, the state of the switch does not change from Off to On, and once clicked again, it is sending the On command instead of Off.
Thats just checking if the harmony hub is in an OFF or ON status.
So its ON whenever you use any of the Activities and is OFF when you press the OFF button on the remote.
You’ll need to check the device if its on. Not the HUB itself.
OK, my understanding was that switch will automatically change itself to On value, once activated from Off value. In such case should I use something different? Or should I add automation which will update the value of the switch entity once the switch was triggered?
No, the template is looking at the Harmony HUB not the device itself. Unless you start an activity it will always show as OFF. And you can only get a status on which activity is active, not which device.
Also looking at your code you are sending an ‘On/Off’ for the turn_on command.
The On/off is correct since thats how the harmony has added the specific activity from its base of devices, which worked only for On command, then I manually added Off command by reading the AC units remote. There is no way to get the state info from device itself, so a workaround is needed. Thus, my question if I should make automation to chenge the entity state in HA.
I’m not 100% sure and cannot test this atm. But i think when u send a command via the hub it will not change its state to ON, it will only do so if an activity is started.
If you are using the Hub only for the AC then you could do it with the activity and it change its state.
Since when an activity is active it will show “ON” on its state
and I will create automation triggered by the event of activating switch, which will then change the value of the state of swich.klima from Off to On. Then on the another activation of the switch it will change the state to Off
The value_template drives which service is used turn_on or turn_off. It also drives the state of the switch. Referencing it self will do nothing as a state has never been reached.
If you want to simulate the device turning on and off because the device does not report a state, then you need to use something to store the state. An input boolean can do that.
The input boolean would be turned on in the turn_on section (you’d add it before or after your existing service), and turned off in the turn_off section. And your value_template would reference the input_boolean.
Just add input_boolean.klima to your helpers, then the following switch template.