Hello Community,
I try to monitor Apple TV usage by exporting datas to Mosquito.
To do that, I created a Node-Red flow
[{"id":"7893ebb564baa428","type":"server-state-changed","z":"434899d.87efa68","g":"69c2dc1d7c9d16d5","name":"Apple TV","server":"df04f5e9.a55d98","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"media_player.salon","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":100,"y":2800,"wires":[["78ae9045cce14eae"]]},{"id":"78ae9045cce14eae","type":"function","z":"434899d.87efa68","g":"69c2dc1d7c9d16d5","name":"","func":"if ( msg.payload == \"playing\" ) {\n msg.payload = \n {\n \"media_title\": msg.data.new_state.attributes.media_title,\n \"app_name\" : msg.data.new_state.attributes.app_name,\n \"media_artist\" : msg.data.new_state.attributes.media_artist,\n };\n\n}\nelse {\n msg.payload = \n {\n \"media_title\": \"\",\n \"app_name\" : \"\",\n \"media_artist\" : \"\",\n };\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":320,"y":2800,"wires":[["0cb2a5dc51911553"]]},{"id":"0cb2a5dc51911553","type":"split","z":"434899d.87efa68","g":"69c2dc1d7c9d16d5","name":"","splt":",","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":470,"y":2800,"wires":[["625b9892399dbc63"]]},{"id":"625b9892399dbc63","type":"switch","z":"434899d.87efa68","g":"69c2dc1d7c9d16d5","name":"","property":"parts.key","propertyType":"msg","rules":[{"t":"eq","v":"media_title","vt":"str"},{"t":"eq","v":"app_name","vt":"str"},{"t":"eq","v":"media_artist","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":630,"y":2800,"wires":[["2591939e0a7d9c89"],["cf2a13d5a4d3a0a7"],["b5f21cd9c9944e8f"]]},{"id":"2591939e0a7d9c89","type":"mqtt out","z":"434899d.87efa68","g":"69c2dc1d7c9d16d5","name":"Apple TV Salon Media Title","topic":"homeassistant/appletv_salon/media_title","qos":"2","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"1c52927f.96163e","x":860,"y":2760,"wires":[]},{"id":"cf2a13d5a4d3a0a7","type":"mqtt out","z":"434899d.87efa68","g":"69c2dc1d7c9d16d5","name":"Apple TV Salon Application","topic":"homeassistant/appletv_salon/application","qos":"2","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"1c52927f.96163e","x":860,"y":2800,"wires":[]},{"id":"b5f21cd9c9944e8f","type":"mqtt out","z":"434899d.87efa68","g":"69c2dc1d7c9d16d5","name":"Apple TV Salon Media Artist","topic":"homeassistant/appletv_salon/media_artist","qos":"2","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"1c52927f.96163e","x":860,"y":2840,"wires":[]},{"id":"df04f5e9.a55d98","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30},{"id":"1c52927f.96163e","type":"mqtt-broker","name":"mosquitto","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
The major problem that I’m facing is the refresh information. Indeed, there are multiple issues :
- Some time, datas are in msg.data.new_state.attributes and sometime in msg.data.attributes
- When I switched from a Youtube video to another, the “event state” node don’t refresh even if I uncheck to ignore change “Current state equals previous state”
Do someone success to implement a monitor of Apple TV usage ?