@joff wrote:
Hi.
Is there an api reference for the hass.states.set python procedure.
I am trying to set a sensor using a python script but keep getting syntax errors. I am sure it’s something simple but seeing some documentation on it would be a great help.I have a template sensor to hold a power total in kWh and am trying to set it with the following:
hass.states.set(output_id, {‘week_total’: “10.5”, ‘unit_of_measurement’: “kWh”, ‘friendly_name’: “Plug Weekly Total”})
(‘output_id’ is a variable entered as service call data when calling the script and defines the entity)
The sensor is defined in my configuration as:
# Sensor to read weekly power consumption of smart plug - platform: template sensors: smart_plug_weekly_total: friendly_name: "Plug Weekly Total" unit_of_measurement: kWh value_template: "{{ attribute('week_total') | float }}"
Any help greatly appreciated.
Posts: 4
Participants: 3