When editing/creating pistons, if you don’t already have them on, turn on:
Show complex IFs
Show when true/false actions
First: Update Existing Netflix Switch
- Update switch triggers to only respond to Physical changes
- Prevents triggering the switch when updating the status in the timer later on.
- Add support for turning off the switch by calling DELETE on /ws/apps/Netflix/run.
- You can now turn off Netflix by turning your switch off.
- Remove auto-off functionality since the status is now also updated by the timer created later.
Seconds: Create New Piston for Polling Status
- Create a new piston and name it something like “Netflix Switch Status Checker”.
- Add a Timer to execute every 30 seconds.
- This is how often we’ll check for status updates.
- Make a GET request to http://<TV_IP>:8001/ws/apps/Netflix
- Add an if expression of $response contains ‘running’ is true
- When 4 is true, do a sanity check if the switch isn’t on, then turn it on. Otherwise do nothing.
- No need to run a command when we don’t have to.
- When 4 is false, do a sanity check if the switch isn’t off, then turn it off. Otherwise do nothing.
FYI, the false case for $response contains ‘running’ can be one of two things:
- When the response body doesn’t contain the text ‘running’, e.g. when Netflix is off the status will be ‘stopped’.
- The the TV is off, the web request will return an empty response.
Let me know if you have any questions.
I built these when others were using the TV and I couldn’t fully test them. Now that the pistons have run for a bit, there is an error where the polling will cause the TV to turn on when it’s off. Will figure out a fix and update this in a bit.