I'm using the command:
However, is not able to detect whether HDMI is connected or not.
Is there other way to detect HDMI status?
tvservice -M is used to monitor for changes to the HDMI status, ie. plugging or unplugging the HDMI cable. tvservice -s will tell you the current status including whether the cable is already plugged in. It will return a hex value, the least significant bit of which tells you the cable is plugged in (value 2) or cable is unplugged (value 1).