Calling Services in Developer Tool:
You open Hass, click the Service button , then in the Service section, you can choose any service. I chose switch.turn_on. Let me explain here a little bit. You want the service switch.turn_on to have the switch in Hass, but since the service article is the basic concept, I have to introduce it first. How to add the switch you are hard to see in the following articles. This article if you do not have a switch, see the add switch and then go back or just see it first. Come on. You choose to switch. Name (your switch name), here I choose switch.lamp. Then press the CALL SERVICE to finish.
You have made a call to service switch.turn_on, which means you have to turn on the light, which means you click on the light on the interface. If the light is off, it will open, if the light is on, open call will not happen.
How to call services in code:
This forces you to learn if you want to continue the code. Perform the Service Tools call in Developer Tools only for the purpose of testing Services, or make quick calls to check. In order to perform the tasks you have to learn how to call the service in code.
You see the following code:
- service: switch.turn_on
entity_id: switch.lamp
The above code will also open the switch.lamp task . Thus, in terms of implementation, it is exactly the same as calling with tools like above. The principle of calling services in code (called in automation, script ..) is bulleted (-) and declared service:. Then down the indentation line on the same line as the above service word, and type entity_id: switch.
Actually ENTITY_ID is a component of the data: . In this service, we only use the name and no other data, so we can omit and call entity_id directly : full must be as follows.
- service: switch.turn_on
data:
entity_id: switch.lamp
The call is simple, isn’t it? Calling this service will be applied in Automation, Script to be able to code automatically open the lights, turn off the lights.