Looking for examples or docs for entity getting states from another entity

This should be a simple bit of code, but I’m having trouble finding any docs or code example, I’d appreciate anyone pointing me to some examples to get me going.

I’m using the heatpump control entity found here (1), but I’d like to write a second component that begins to tie together my heatpump with my radiator heat. I’m looking at modifying the generic thermostat entity to start building up the logic to control the pair, but for the life of me I can’t figure out how to read the state and temperature from the heatpump entity, and to ultimately call set_state against the heatpump.

  1. https://github.com/SwiCago/HeatPump/blob/master/integrations/home-assistant.io/mitsubishi_mqtt.py

Do you have the mitsubishi_mqtt.py working? If so, go to the state page on the front end and look for the entity. You can see all the states and attributes which you can create a separate temp sensor if you want. Another way is to make a mqtt sensor and just subscribe to the mqtt feed for temp.

The mitsubishi_mqtt.py is working just fine. What I’m fighting with right now is being able to get the state out of a heatpump entity. Right now my code looks like this:

def async_update(self):
    """Update the state of the sensor."""
    _LOGGER.warning('all states: {0}'.format(self._hass.states))
    heatpump_states = self._hass.states.get(self._heatpump_entity_id)
    _LOGGER.warning('hp name: {0}, state: {1}'.format(self._heatpump_entity_id, heatpump_states))
    self._state = heatpump_states.attributes.get('current_temperature')
    _LOGGER.debug("New temperature: %s", self._state)

Full code for the component is here: https://github.com/alexholman/home_assistant/blob/master/custom_components/sensor/heatpump_temp.py

But in the HA logs shows that I receive None from the _hass.states.get(

2018-03-11 04:05:23 WARNING (MainThread) [custom_components.sensor.heatpump_temp] hp name: climate.1st_fl_heatpump, state: None
2018-03-11 04:05:24 ERROR (MainThread) [homeassistant.components.sensor] Error on device update!
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 217, in async_add_entity
    yield from entity.async_device_update(warning=False)
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity.py", line 304, in async_device_update
    yield from self.async_update()
  File "/usr/lib/python3.5/asyncio/coroutines.py", line 210, in coro
    res = func(*args, **kw)
  File "/home/homeassistant/.homeassistant/custom_components/sensor/heatpump_temp.py", line 75, in async_update
    self._state = heatpump_states.attributes.get('current_temperature')
AttributeError: 'NoneType' object has no attribute 'attributes'

I know I have the correct entity id because cut and pasting from my HA states panel I have an entry for climate.1st_fl_heatpump

Ever get to the bottom of this?

Take a look on climate/generic_thermostat.py and async_track_state_change. It should provide some pointers.