Automation Tv and lights / nello and lights

Hallo Community,
first I want to apologize for my English.
I connected a couple of smart home devices to my home assistant. And so far it runs great.
Now I want to create two automations. But I have no idea of this code thing {} etc.
perhaps the professionals can help me.
1 automation
If tv (Sony Bravia) is on (a trigger could be if chrome cast in home assistant is available or not?) then the lights (https://www.home-assistant.io/components/light.limitlessled/) are dimming to 50%. if tv is off back to 100%

2 automation
If the doorbell ring (https://www.home-assistant.io/components/lock.nello/) then the lights turning green and back to white.

Thanks a lot

Does this help? example

Thanks for the example. I understand that this is the case if I stream media. But I mean when I turn on the tv