Odroid C2-when TV is on, run a script, when off, run another script

command in terminal: echo scan | cec-client -s -d 1
then i see this:
CEC bus information

device #0: TV
address: 0.0.0.0
active source: no
vendor: Toshiba
osd string: TV
CEC version: 1.4
power status: on
language: eng

device #1: Recorder 1
address: 2.0.0.0
active source: no
vendor: Toshiba
osd string: CECTester
CEC version: 1.4
power status: on
language: eng

looks about right. my Odroid C2 is on hdmi port #2.
how do i make ubuntu run a script when TV is turned on?
how do i make ubuntu run another script when TV is turned off?