sensor.greenely icon indicating copy to clipboard operation
sensor.greenely copied to clipboard

Min, max and mean prices for today and tomorrow

Open juancameijeiras opened this issue 3 years ago • 1 comments

Not a bug! But an enhancement request. In order to make the sensors more useful is to have as part of the main sensor for prices or to have it as separate sensors, the min, max and mean price for the day and next day.

juancameijeiras avatar Sep 17 '22 09:09 juancameijeiras

Heyo.

I don't really know how to work out mean price but I have a solution in node red for min and max:

[{"id":"ae91db74e150a110","type":"api-current-state","z":"53610d83cea0558f","name":"Greenely Prices","server":"1101e9cb.075866","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.greenely_prices","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","x":520,"y":500,"wires":[["142294e2cf4fcd42"]]},{"id":"142294e2cf4fcd42","type":"function","z":"53610d83cea0558f","name":"Process Data","func":"//Nuvarande pris\nconst priceNow = msg.payload;\n\n//Räkna ut min- och max-priser\nlet prices = msg.data.attributes.current_day\nlet priceMin = prices[0].price\nlet priceMax = prices[0].price\n\nprices.forEach(el => {\n if (el.price < priceMin) priceMin = el.price\n})\n\nprices.forEach(el => {\n if (el.price > priceMax) priceMax = el.price\n})\n\n\n//Bygg vår payload\nmsg.payload = {\n priceNow,\n priceMin,\n priceMax\n}\n\n//Jalla let go\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":500,"wires":[["0d7c3a695110472e"]]},{"id":"0d7c3a695110472e","type":"debug","z":"53610d83cea0558f","name":"Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":970,"y":500,"wires":[]},{"id":"1101e9cb.075866","type":"server","name":"Home Assistant","version":4,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"}]

gust4vsson avatar Oct 04 '22 20:10 gust4vsson