Search code examples
pythonpython-3.xentitystate

how to get datetime from entity (remote.get_states(api)]


im using python to save the values of sensors in csv file. I dont know how can i get the timesstamp from intity. This is the entity:

<state sensor.aeotec_zw074_multisensor_gen5_luminance=1000.0; value_id=72057594076479538, value_instance=1, node_id=2, friendly_name=Aeotec ZW074 MultiSensor Gen5 Luminance, value_index=3, unit_of_measurement=lux, new_entity_id=sensor.aeotec_zw074_multisensor_gen5_luminance, old_entity_id=sensor.aeotec_zw074_multisensor_gen5_luminance_2_3 @ 2017-10-17T12:57:14.532186+00:00>

this the script yhat iam using and i want to expand time as well:

aeotec_zw074_multisensor_gen5_temperature = remote.get_state(api, ‘sensor.aeotec_zw074_multisensor_gen5_temperature’)
print(’{} is {} {}.’.format(aeotec_zw074_multisensor_gen5_temperature.name,
aeotec_zw074_multisensor_gen5_temperature.state,
aeotec_zw074_multisensor_gen5_temperature.attributes[‘unit_of_measurement’]
)

)

Could someone help me how to get time @ 2017-10-17T12:57:14.532186+00:00 from entity please?


Solution

  • import homeassistant.remote as remote
    api = remote.API('127.0.0.1', 'YOUR_PASSWORD')
    data = remote.get_state(api, 'sensor.random_sensor')
    print(data.last_changed)