This page is not a full documentation it’s more a collection of some example. A simple way to get all current entities is to visit the “Set State” page in the “Developer Tools”. For the examples below just choose one from the available entries. Here the sensor sensor.office_temperature and the switch switch.livingroom_pin_2 are used.
Similar to the output in the “Developer Tools” of the frontend
12345678910111213
importhomeassistant.remoteasremoteapi=remote.API('host','password')print('-- Available services:')services=remote.get_services(api)forserviceinservices:print(service['services'])print('\n-- Available event')events=remote.get_event_listeners(api)foreventinevents:print(event)
Get the state of an entity
To get the details of a single entity the get_state method is used.
123456789
importhomeassistant.remoteasremoteapi=remote.API('host','password')office_temperature=remote.get_state(api,'sensor.office_temperature')print('{} is {} {}.'.format(office_temperature.attributes['friendly_name'],office_temperature.state,office_temperature.attributes['unit_of_measurement']))
The output is composed out of the details which are stored for this entity.
1
Office Temperature is 19 °C.
The exact same thing is working for a switch. The difference is that both entities have different attributes.
12345678
importhomeassistant.remoteasremoteapi=remote.API('host','password')switch_livingroom=remote.get_state(api,'switch.livingroom_pin_2')print('{} is {}.'.format(switch_livingroom.attributes['friendly_name'],switch_livingroom.state))