I need to add an if/else condition in this function that checks the on/off value of the home assistant entity but not sure how to call it inside the function node, can someone advise?
Is the entity in the message going into the function? If so there’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.
Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.
If you can't make it work then use the copy path button described above to copy the message contents and paste it here so we can see what is there.