We have a litter robot 4 that takes the weights of our cats. I want to be able to graph the weight of the cats on separate charts and also throw away any bad data, when they are both in the litterbox or like half in it. I had this for one cat and then duplicated it for the other cta but it only worked for the first one in the yaml.
- platform: template
sensors:
flint_pet_weight:
value_template: >
{% set x = states('sensor.litter_robot_4_pet_weight')|float %}
{% if 8.8 <= x <= 10 %}
{{ x }}
{% else %}
unknown
{% endif %}
- platform: statistics
name: "Flint Weight"
entity_id: sensor.flint_pet_weight
state_characteristic: mean
max_age:
I then tried something like this but this doesnt work for either of them
- platform: template
sensors:
flint_pet_weight:
value_template: >
{% set x = states('sensor.litter_robot_4_pet_weight')|float %}
{% if 8.8 <= x <= 10 %}
{{ states('sensor.flint_pet_weight') }}
{% elif 7 <= x <= 8.7 %}
{{ states('sensor.flora_weight') }}
{% else %}
unknown
{% endif %}
- platform: statistics
name: "Flint Weight"
entity_id: sensor.flint_pet_weight
state_characteristic: mean
max_age:
hours: 168
- platform: statistics
name: "Flora Weight"
entity_id: sensor.flora_weight
state_characteristic: mean
max_age:
hours: 168
The state only changes, when the weight is within the specified range. It requires that the scale resets quickly enough (I know from our cats that they go to the toilet one right after the other).
The attributes part is only a nice-to-have. You can drop it. I stumbled upon it a while ago here. The [:6] means that the last 6 state changes will be recorded.
- platform: template
sensors:
flint_pet_weight:
unit_of_measurement: lb # I hope this is not kg :)
availability_template: "{{ states('sensor.litter_robot_4_pet_weight')|is number and 8.8 < states('sensor.litter_robot_4_pet_weight') <= 10 }}"
value_template: "{{ states('sensor.litter_robot_4_pet_weight')|float(0) }}"
flora_pet_weight:
unit_of_measurement: lb
availability_template: "{{ states('sensor.litter_robot_4_pet_weight')|is number and 7 < states('sensor.litter_robot_4_pet_weight') <= 8.7 }}"
value_template: "{{ states('sensor.litter_robot_4_pet_weight')|float(0) }}"
- platform: statistics
name: "Flint Weight"
entity_id: sensor.flint_pet_weight
state_characteristic: mean
max_age:
hours: 168
- platform: statistics
name: "Flora Weight"
entity_id: sensor.flora_weight
state_characteristic: mean
max_age:
hours: 168
Note it is not recommended that you use this old template sensor format. The new format would look like this:
configuration.yaml
template:
- sensors:
- name: Flint Pet Weight
unit_of_measurement: lb # I hope this is not kg :)
availability: "{{ states('sensor.litter_robot_4_pet_weight')|is number and 8.8 < states('sensor.litter_robot_4_pet_weight') <= 10 }}"
state: "{{ states('sensor.litter_robot_4_pet_weight')|float(0) }}"
- name: Flora Pet Weight
unit_of_measurement: lb
availability: "{{ states('sensor.litter_robot_4_pet_weight')|is number and 7 < states('sensor.litter_robot_4_pet_weight') <= 8.7 }}"
state: "{{ states('sensor.litter_robot_4_pet_weight')|float(0) }}"
any way to get this a bit more dynamic VS setting the cats weight range? like I have two cats one weight 5lb and the other 6lb but are growing. is there away to say take a snapshot of the two current values and then match based of a small growth in the number?