Two days, and I’m now asking a second question - my searching abilities are feeling really inadequate - it only seems to turn up questions about setting states in a lambda, and not having problems reading states.
Some code:
select:
- platform: template
name: Status
id: status
options:
- "State1"
- "State2"
- "State3"
- "State4"
initial_option: "State1"
optimistic: true
restore_value: true
set_action:
- logger.log:
format: "Status changed to: %s"
args: ["x.c_str()"]
- button.press: update
switch:
- platform: template
name: Enable
id: enable
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
turn_on_action:
- logger.log: "Enable on"
- button.press: update
turn_off_action:
- logger.log: "Enable off"
- button.press: update
- platform: template
name: Night
id: night
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
turn_on_action:
- logger.log: "Night on"
- button.press: update
turn_off_action:
- logger.log: "Night off"
- button.press: update
button:
- platform: template
name: Update
id: update
on_press:
- logger.log:
format: "Update: State=\"%s\", Night=%s, Enable=%s"
args: [ 'id(status).state.c_str()', 'id(night).state ? "Night" : "Day"', 'id(enable).state ? "Enabled" : "Disabled"' ]
The idea is that I have a couple of switches and a select, that together describe the overall state of the device. If any of them change, I want to call the press action on the Update button. This reads the state of the select and switches, and uses a fair bit of conditional logic to update a combined status light (that logic is not shown.) I don’t have a problem with that logic, the problem is that the Update button’s on_press automation reads the state of what the switches were at boot, and always reads States for the select.
If I change one of the switches or the select, the log shows that the component has changed state, and that the Update on_press is called, but the on_press automation doesn’t reflect the new state.
If I change the states of the “input” components, and restart the node, the Update on_press automation properly logs the new switch states, but still says State2 for the select. If I subsequently change the state of the “input” components, the Update automation still shows the boot up state, whether it’s called as a result of changing the “input” component or manually pressing the Update button in HA.
I don’t understand why the current state isn’t being read. I’m clearly doing something wrong, but what?