Making progress - need a little more assistants
my sensor is now:
- sensor:
- name: Office PID
unique_id: koko_auto_0003
state: >
{% set feedback = states('sensor.office_lighting_illuminance') | int %}
{% set kp = state_attr('sensor.living_room_pid','P' ) | float | default(2) %}
{% set ki = state_attr('sensor.living_room_pid','I') | float | default(0.0) %}
{% set kd = state_attr('sensor.living_room_pid','D') | float | default(0.0) %}
{% set sp = state_attr('sensor.living_room_pid','Set_point') | int | default(800) %}
{% set lst_input = state_attr('sensor.living_room_pid','last_input') | int | default(810) %}
{% set lst_error = state_attr('sensor.living_room_pid','last_error') | int | default(10.0) %}
{% set error = (sp - feedback) | int %}
{% set delta_error = (error - lst_error) | float %}
{% set nwtime = now().timestamp() %}
{% set lsttime = as_timestamp(states.sensor.living_room_pid.last_changed) %}
{% set delta_time = (nwtime-lsttime) %}
{% set disp = ((kp*error)+(ki*error*delta_error)+(kd*delta_error/delta_time)) | float %}
{{disp}}
attributes:
P: >
{% set disp = 0.015 |float(3) %}
{{ disp }}
I: >
{% set disp = 0.0 |float(3) %}
{{ disp }}
D: >
{% set disp = 0.01 |float(3) %}
{{ disp }}
Set_point: >
{% set disp = 800 |int %}
{{ disp }}
last_error: >
{% set feedback = states('sensor.office_lighting_illuminance') | int %}
{% set sp = state_attr('sensor.living_room_pid','Set_point') | int | default(800) %}
{% set disp = (sp - feedback) | int %}
{{ disp }}
last_input: >
{% set disp = states('sensor.office_lighting_illuminance') | int %}
{{ disp }}
I will be setting the P I and D by going into Developer tools - this is working since it has a unique_id.
I will be setting the set point by automation based on time and request.
Otherwise I would like it to reference itself for the information that is currently coming from ‘living_room_pdi’
How do I get this sensor located in the template: !include_dir_merge_list → [path]/office_pid.yaml to reference itself?
I’ve tried replacing
state_attr(‘sensor.living_room_pid’,‘P’ )
with
state_attr(‘sensor.office_pid’,‘P’ )
and
this.attribute.P
… (several other attempts)