Im trying to get a list of entitles, their state, and selected attributes or reject specific ones. While also doing mathematical evaluations as needed.
Sensor.baby_feeding_1 [state] 2 (oz) [attributes] time (00:30) , duration (00:30:00)
Sensor.baby_feeding_2 [state] 1.2 (oz) [attributes] time (03:30) , duration (00:42:00)
Sensor.baby_feeding_3 [state] 1.5 (oz) [attributes] time (06:30) , duration (00:35:00)
Many more entries but you get the idea
1st scenario) In the above Iād like to list feeding times between 03:30 and 06:30 without the duration attribute
2nd scenario) In the above Iād like to sum the total oz , as well as duration (total)
3rd scenario) In the above Iād like to count the total feedings for the day
I KNOW thats quite a bit, but, figured it would be better to ask all at once than separate posts.
Letās start with the basics. Find the name of the integration responsible for generating those sensors and use it in the following template. For example, if itās ābaby_managerā then enter the following into the Template Editor.
{{ integration_entities('baby_manager') }}
The result will be a list of all entities produced by that integration. Let me know when you have it working and then we can proceed with building upon it to produce the 3 things you want.
What is the integrationās name? Its full name (and, ideally, the link to its Github repo because this appears to be a custom integration) and the name you used in integration_entities().
According to the list of entity_ids you posted, there are no sensor entities like what you described in your first post. Whatās the reason for this discrepancy?
Primarily, the reason for the difference in the entities and what I posted was simply high level because I want to learn how to write them based off scenarios (clearly not helpful) and ultimately not just have a posted question then given the answer and learn nothing from it.
Hereās the basic framework. Start with a list of entity_ids for all entities in the var integration, select the entity_ids containing the string feeding, get the state value of each one (it will be a string value), convert string to float (floating point number), and finally compute the sum. The result represents the total quantity of liquid for all feedings. Let me know if it works correctly or fails.
The time and duration attributes probably contain string values as well. Letās confirm that assumption. Let me know whatās reported by this template:
{{ state_attr('var.feeding_1', 'time') }}
{{ state_attr('var.feeding_1', 'duration') }}
{{ state_attr('var.feeding_1', 'time') is string }}
{{ state_attr('var.feeding_1', 'duration') is string }}
Assuming time and duration contain string values and time is always in HH:MM format, try this template. It should report the total duration of all feedings whose times are between 03:30 and 06:30.
The first two lines are identical to the previous example.
It expands each feeding entity_id into its State Object (which contains lots of information about the entity).
It selects time values greater than or equal to 03:30. This is actually a string comparison, not an arithmetic comparison. However, owing to the way time values are numbers in a rigid format, a string comparison will work as desired.
It selects time values less than or equal to 06:30.
It extracts the duration values, converts them into timedelta objects and finally computes the sum.